Search Interview Questions  3335 questions in repository. There are more than 200 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. 

 
Data Structure  Interview Questions and Answers for 'Linkedlist'  21 question(s) found  Order By Newest  
Frequently asked.  
_{}
 
Ans. ArrayList are implemented in memory as arrays and hence allows fast retrieval through indices but are costly if new elements are to be inserted in between other elements. LinkedList allows for constanttime insertions or removals using iterators, but only sequential access of elements 1. Retrieval  If Elements are to be retrieved sequentially only, Linked List is preferred. 2. Insertion  If new Elements are to be inserted in between other elements , Linked List is preferred. 3. Search  Binary Search and other optimized way of searching is not possible on Linked List. 4. Sorting  Initial sorting could be pain but lateral addition of elements in a sorted list is good with linked list. 5. Adding Elements  If sufficiently large elements needs to be added very frequently ,Linked List is preferable as elements don't need consecutive memory location.  
Sample Code for ArrayList Sample Code for LinkedList  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve java collections list arraylist linkedlist difference between architecture data structure ebay Asked in 2 Companies basic frequentCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
Try 2 Question(s) Test  
Very frequently asked. Favorite question in Walk in Drive of many Indian service companies.  
_{}
 
Ans. Underlying data structure for ArrayList is Array whereas LinkedList is the linked list and hence have following differences  1. ArrayList needs continuous memory locations and hence need to be moved to a bigger space if new elements are to be added to a filled array which is not required for LinkedList. 2. Removal and Insertion at specific place in ArrayList requires moving all elements and hence leads to O(n) insertions and removal whereas its constant O(1) for LinkedList. 3. Random access using index in ArrayList is faster than LinkedList which requires traversing the complete list through references. 4. Though Linear Search takes Similar Time for both, Binary Search using LinkedList requires creating new Model called Binary Search Tree which is slower but offers constant time insertion and deletion. 5. For a set of integers you want to sort using quicksort, it's probably faster to use an array; for a set of large structures you want to sort using selection sort, a linked list will be faster.  
Sample Code for ArrayList Sample Code for LinkedList  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve collections java data structures arraylist linkedlist Asked in 61 Companies Basic frequentCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
Try 1 Question(s) Test  
_{}
 
Ans. public class LinkedList { Node start = null; Node head = null; class Node{ Integer body; Node nextNode; Node(Integer value){ body = value; } } private void insertInMiddle(Integer value){ head = start; if(start == null) { start = new Node(value); head = start; head.nextNode = null; return; } while(head.body < value){ if(head.nextNode == null  head.nextNode.body >= value){ Node newNode = new Node(value); newNode.nextNode = head.nextNode; head.nextNode = newNode; break; } head = head.nextNode; } } private void traverse(){ head = start; while(head != null){ System.out.println(head.body); head = head.nextNode; } } public static void main(String[] args){ LinkedList ll = new LinkedList(); ll.insertInMiddle(5); ll.insertInMiddle(10); ll.insertInMiddle(15); ll.insertInMiddle(7); ll.traverse(); } }  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve LinkedList Data structures AlgorithmCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
 
Ans. LinkedList and ArrayList are two different implementations of the List interface. LinkedList implements it with a doublylinked list. ArrayList implements it with a dynamically resizing array.  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve java collections list arraylist linkedlist difference between basic frequentCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
Ans. First Find the number of nodes in the linked list and take it as n.then find the data at n3 element.  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve linkedlist Asked in 1 CompaniesCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
Ans. public class LinkedList { Node start = null; Node head = null; class Node { Integer body; Node nextNode; Node(Integer value) { body = value; } } private void addNodeToEnd(Integer value) { if (start == null) { start = new Node(value); head = start; head.nextNode = null; return; } while (head.nextNode != null) { head = head.nextNode; } head.nextNode = new Node(value); } private void traverse() { head = start; while (head != null) { System.out.println(head.body); head = head.nextNode; } } public static void main(String[] args) { LinkedList ll = new LinkedList(); ll.addNodeToEnd(5); ll.addNodeToEnd(10); ll.addNodeToEnd(15); ll.traverse(); } }  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve LinkedList Data structures AlgorithmCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
Ans. public class LinkedList { Node start = null; Node head = null; class Node { Integer body; Node nextNode; Node(Integer value) { body = value; } } private void addNodeToEnd(Integer value) { if (start == null) { start = new Node(value); head = start; head.nextNode = null; return; } while (head.nextNode != null) { head = head.nextNode; } head.nextNode = new Node(value); } private void deleteNode(Integer value) { head = start; while (head.nextNode != null) { if(head.nextNode.body == value){ head.nextNode = head.nextNode.nextNode; } head = head.nextNode; } } private void traverse() { head = start; while (head != null) { System.out.println(head.body); head = head.nextNode; } } public static void main(String[] args) { LinkedList ll = new LinkedList(); ll.addNodeToEnd(5); ll.addNodeToEnd(10); ll.addNodeToEnd(15); ll.traverse(); ll.deleteNode(10); ll.traverse(); } }  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve linkedlist delete node from linkedlistCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
Ans. A List is an child interface of collection interface in java where as Linked list is and implementation class of List interface which has doubly linked as a underlying data structure  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve linkedlist list vs linkedlist Asked in 1 CompaniesCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
 
Ans. No, Generic parameters cannot be primitives.  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve java collections list linkedlist generics yesnoCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
Ans. All are correct.  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve java generics linkedlist list collections basicCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
Ans. Array List works on Array and when we add an element in middle of the list, Array List need to update the index of all subsequent elements. I the capacity is full, it even may need to move the whole list to a new memory location . Linked List works on Double linked list algorithm and all it has to do is to adjust the address of the previous and next elements.  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve arraylist vs linkedlist collections list Asked in 2 CompaniesCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
^{This question was recently asked at 'Kony Labs,Compro Technologies'.This question is still unanswered. Can you please provide an answer.}  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve Linkedlist data structures algorithm Asked in 2 Companies basicCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
^{This question was recently asked at 'Caprus IT'.This question is still unanswered. Can you please provide an answer.}  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve linkedlist delete a node from linked list Asked in 1 CompaniesCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
Ans. Initialize an ArrayList that will hold LinkedLists i.e every element of the arraylist will be a linked list. Such collection could be used in algorithms that require first random access and then sequential traversal. For example  Storing traversal paths for a graph wherein we can start from any vertex. Implementing dictionary with each arraylist element holding staring with character and then linked list holding duplicate words.  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve collections linkedlist arraylistCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
^{This question is still unanswered. Can you please provide an answer.}  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve Arraylist linkedlist queue collectionsCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
^{This question was recently asked at 'Ancestry'.This question is still unanswered. Can you please provide an answer.}  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve linkedlist internal implementation of linkedlist Asked in 1 CompaniesCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
Ans. Arrays allows elements to be accessed directly using the index. As Array elements are stored in continuous memory locations it's very easy to find the memory address of any element using the formula as following Memory Address of Array start or index 0 + ( Size of array element * Index )  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve arrays linkedlistCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
Ans. public class LinkedList { Node start = null; Node head = null; class Node { Integer body; Node nextNode; Node(Integer value) { body = value; } } public static void main(String[] args) { LinkedList ll = new LinkedList(); ll.addNodeToEnd(5); ll.addNodeToEnd(10); ll.addNodeToEnd(15); ll.traverse(); if(checkIfLoop(l1)){ System.out.println("There is a Loop"); } else { System.out.println("No Loop"); } } private boolean checkifLoop(Test l1) { Node slow = start; Node fast = start; Node faster = start; while(slow != null ) { fast = slow.nextNode; faster = fast.nextNode; if(slow == fast  slow == faster) { return true; } slow = slow.nextNode; } return false; } } Complexity of this algorithm is O(n)  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve LinkedList Cyclic LinkedListCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
^{This question was recently asked at 'Canopy Tax'.This question is still unanswered. Can you please provide an answer.}  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve LinkedList Asked in 1 CompaniesCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
^{This question is still unanswered. Can you please provide an answer.}  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve arrays vs linkedlistCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  
_{}
 
Ans. Work with two pointers on the linked list  a slow pointer (increments by one node) and a fast pointer (increments by two nodes). If both of these pointers meet at the same node, then there is a cycle in the linked list. Otherwise, no cycle.  
Help us improve. Please let us know the company, where you were asked this question :  
_{ Like Discuss Correct / Improve linkedlist Asked in 1 CompaniesCorrectionDuplicate of Another QuestionCompany where this question was AskedSuggestion}  