Java - Interview Questions and Answers for 'Data structure' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Data structure' - 26 question(s) found - Order By Newest

Frequently asked.
 Q1. If you are given a choice to use either ArrayList and LinkedList, Which one would you use and Why ?Core Java
Admin
info@buggybread.com
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 constant-time 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 , Array 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.

 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      basic        frequent

Try 2 Question(s) Test


Advanced level question frequently asked in US based companies. Recently asked in EMC and Intuit.
  Q2. Can you provide some implementation of a Dictionary having large number of words ? Solution
Admin
info@buggybread.com
Ans. Simplest implementation we can have is a List wherein we can place ordered words and hence can perform Binary Search.

Other implementation with better search performance is to use HashMap with key as first character of the word and value as a LinkedList.

Further level up, we can have linked Hashmaps like ,

hashmap {
a ( key ) -> hashmap (key-aa , value (hashmap(key-aaa,value)
b ( key ) -> hashmap (key-ba , value (hashmap(key-baa,value)
....................................................................................
z( key ) -> hashmap (key-za , value (hashmap(key-zaa,value)
}

upto n levels ( where n is the average size of the word in dictionary.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   collections   hashmap   binary search   search algorithm   advanced   architecture   data structure     Dell EMC   Intuit   Corporate Brokers  PWC India  Yahoo  Oracle        frequent

Try 1 Question(s) Test


Very frequently asked. Favorite question in Walk in Drive of many Indian service companies.
  Q3. What is the difference between ArrayList and LinkedList ?Core Java
admin
info@buggybread.com
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     Deutsche Bank  Overstock.com  HCL Technologies  Infosys  EBay  The Advisory Board Company  Accuity  JC Penney  Cerner  Chase  Amazon  Deloitte  Deegit  Tata Consultancy  Cognizant (CTS)  IBM  Accenture  Mindtree  ESRI  QwikCilver Solutions  TMC Bonds  GumGum  EMC  Yelp  Classteacher Learning System  FactSet  Simply Hired  SalesForce  Royall & Company  Indeed  eClinicalWorks  TravelClick  State Farm  Manhattan Associates  GoEuro  Veeva Systems  Ness Technologies  Marlabs  Rolta  Volante Technologies  Happiest Minds Technologies  Coviam  Velocify  zanox  SimplyHired  IDBI Intech  Wissen Infotech  Nike  OnDot  PexSupply  Pramati Technologies  Credit Agricole  Mastek  Six Dee Telecom  Accuity  Kellton Tech      Basic        frequent

Try 1 Question(s) Test


 Q4. In a Linked list with sorted numbers, insert a new numbers while maintaining the sort order.Algorithm2017-07-25 14:59:01

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  Algorithm


 Q5. What is the difference between Data Type and Data Structure ?Core Java
Admin
info@buggybread.com
Ans. Data type: a set of values together with operations on that type
Data structure: a physical implementation of a data type

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   data structure   data type


 Q6. Do you see Class as a Data Type or Data Structure ?
Admin
info@buggybread.com
Ans. Class can be better seen as Data Type. This could be implemented as a Data Structure too in some cases.

One thing worth understanding here is that Data type and Data structure are conceptual things. Class could be implementation of either of these.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   class   data type   data structure


 Q7. How to determine if the linked list has a cycle in it ?
admin
info@buggybread.com
Ans. http://stackoverflow.com/questions/494830/how-to-determine-if-a-linked-list-has-a-cycle-using-only-two-memory-locations

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     linked list   data structure   algorithm   java   ebay


 Q8. What is a BlockingQueue?Data Structures
admin
info@buggybread.com
Ans. BlockingQueue is a Queue that supports operations that wait for the queue to become non-empty when retrieving and removing an element, and wait for space to become available in the queue when adding an element.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     blockingqueue   collections   java   concurrent collections     Computer sciences corporation (csc)


 Q9. Which Data Structure should be used for Load Balancer ?

Ans. [ Open Ended question ]

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     data structures   open ended questions   load balancer



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Write a Program to reverse a Linked List ?Data Structure2016-12-13 14:58:09

 This question was recently asked at 'Myntra,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          Myntra  Compro Technologies


 Q11. What is the difference between circular queue and priority queue ?Data Structures2017-01-28 14:43:39

 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     circular queue  priority queue  queue  data structures  collections


 Q12. Write program to create a linked list and perform different operations on it.Algorithm2017-02-24 14:18:01

 This question was recently asked at 'Kony Labs'.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     Kony Labs      basic


 Q13. Write a Program to delete a node from Linked List ?Data Structure2017-05-25 08:22:58

 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     Caprus IT


 Q14. What data structure will you use if we have to search an element in million of elements ?Data Structure2017-03-03 14:38:28

 This question was recently asked at 'Microsoft'.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          Microsoft


 Q15. Write a Program to find the middle element of Linked List ?Data Structure2017-03-27 08:39:28

 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     data structure  linked list


 Q16. Write a Program to merge two sorted arrays ?Data Structure2017-03-27 08:46:57

 This question was recently asked at 'Compro Technologies,ECI Telecom'.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  merge sorted arrays     Compro Technologies  ECI Telecom


 Q17. Find the third last element in a linked list ?Data Structure2017-03-27 08:53:16

 This question was recently asked at '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     Compro Technologies


 Q18. Implement stack using generics in Java.Data Structure2017-04-18 09:23:44

 This question was recently asked at 'Bind Software Innovations'.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     oding  cod     Bind Software Innovations


 Q19. How to implement a hashtable ?Data Structure2017-04-20 09:38:10

 This question was recently asked at 'MarkMonitor'.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     hashtable     MarkMonitor



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. What is the difference between Stack and Queue ?Data Structures2017-06-18 18:10:36

Ans. Stack is based on Last in First out (LIFO) principle while a queue is based on FIFO (First In First Out) principle.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     data structure  stack vs queue  stack  queue      Basic


 Q21. Difference between Tree and Graph ?Data Structures2017-07-23 08:18:43

Ans. Graph contain cycles whereas Trees cannot.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     graph  trees  data structures  tree vs graph


 Q22. Write a program for LinkedList, with method to append node and traversing the list ?Algorithm2017-07-25 14:31:33

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  Algorithm


 Q23. Write method to delete Node from a LinkedList.Data Structure2017-07-25 15:09:59

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 linkedlist


 Q24. In a Tree, find common ancestor of two nodes.Data Structures2017-08-24 21:45:59

 This question was recently asked at 'Amazon'.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     Tree  Data structures     Amazon


 Q25. Which Data structure can be used for creating Queue ?Data Structure2017-08-28 17:06:49

 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     queue  collections  data structure


 Q26. Which of the two - Arrays or LinkedList - is a better data structure for implementing Queue ? and Why ?Data Structure2017-08-28 19:34:12

 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  collections




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: