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

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

next 30
 Q11. What is the difference between pop and peek function of stack ?Data Structure
Ans. pop method pulls the top element from the stack and then move the top to the next element whereas peek only get the top element but doesn't move the top.

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

   Like         Discuss         Correct / Improve     stack


 Q12. What is the difference between Data Type and Data Structure ?Core Java
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


 Q13. Do you see Class as a Data Type or Data Structure ?
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


 Q14. How to determine if the linked list has a cycle in it ?
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


 Q15. 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


 Q16. Explain what happens when insertion is performed in case of ArrayList and LinkedList.Data Structure
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 Companies


 Q17. What is the difference between circular queue and priority queue ?Data Structures
Ans. https://qr.ae/TWK2Ok

 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


 Q18. Write program to create a linked list and perform different operations on it.Algorithm
Ans. import java.util.*;
class LinkedListSolution{
protected LinkedList list;
public LinkedListSolution(){
list = new LinkedList();
}
public Object pop() throws NoSuchElementException{
if(list.isEmpty())
throw new NoSuchElementException();
else
return list.removeFirst();
}
public void push(Object obj){
list.addFirst(obj);
}
public Object peek() throws NoSuchElementException{
if(list.isEmpty())
throw new NoSuchElementException();
else
return list.getFirst();
}
public boolean isEmpty(){
return list.isEmpty();
}
public String toString(){
return list.toString();
}
}
class TestStack{
public static void main(String args[]){
LinkedListSolution s = new LinkedListSolution();
s.push("First");
s.push("Second");
s.push("Third");
System.out.println("Top: " s.peek());
s.push("Fourth");
while(!(s.isEmpty()))
System.out.println(s.pop());
}
}

 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      basic


 Q19. Write a Program to delete a node from Linked List ?Data Structure
 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 Companies


 Q20. What data structure will you use if we have to search an element in million of elements ?Data Structure
 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     Search     Asked in 1 Companies


 Q21. Write a Program to find the middle element of Linked List ?Data Structure
 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


 Q22. Write a Program to merge two sorted arrays ?Data Structure
Ans. We can merge two sorted array by using quick sort algorithm

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

   Like         Discuss         Correct / Improve     arrays  merge sorted arrays     Asked in 2 Companies


 Q23. Implement stack using generics in Java.Data Structure
 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     Asked in 1 Companies


 Q24. How to implement a hashtable ?Data Structure
 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     Asked in 1 Companies


 Q25. What is the difference between Stack and Queue ?Data Structures
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


 Q26. Difference between Tree and Graph ?Data Structures
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


 Q27. Write a Program to implement stack using LinkedList.Data Structure
 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


 Q28. Describe how you could use a single array to implement three stacksAlgorithm
 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


 Q29. Write a program to sort a stack in ascending order You should not make any assumptions about how the stack is implemented The following are the only functions that should be used to write this program: push | pop | peek | isEmptyAlgorithm
 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 Structures


 Q30. In a Tree, find common ancestor of two nodes.Data Structures
 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     Asked in 1 Companies


 Q31. Which Data structure can be used for creating Queue ?Data Structure
 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


 Q32. Which of the two - Arrays or LinkedList - is a better data structure for implementing Queue ? and Why ?Data Structure
 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


 Q33. Write a program for binary tree ?Data Structure
Ans. public class BinarySearchTree {
//Represent the node of binary tree
public static class Node {
int data;
Node left;
Node right;
public Node(int data) {
//Assign data to the new node, set left and right children to null

this.data = data;
this.left = null;
this.right = null;
}
}
//Represent the root of binary tree

public Node root;
public BinarySearchTree() {
root = null;
}

//factorial() will calculate the factorial of given number

public int factorial(int num) {
int fact = 1;
if (num == 0) return 1;
else {
while (num > 1) {
fact = fact * num;
num--;
}
return fact;
}
}

//numOfBST() will calculate the total number of possible BST by calculating Catalan Number for given key

public int numOfBST(int key) {
int catalanNumber = factorial(2 * key) / (factorial(key 1) * factorial(key));
return catalanNumber;
}
public static void main(String[] args) {
BinarySearchTree bt = new BinarySearchTree();

//Display total number of possible binary search tree with key 5

System.out.println("Total number of possible Binary Search Trees with given key: "
bt.numOfBST(5));
}
}

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

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q34. Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.Data Structure
 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     arrays  coding  code     Asked in 1 Companies


 Q35. What are the ways to get the values from list ?Data Structure
Ans. list.get(index);

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

   Like         Discuss         Correct / Improve     list     Asked in 1 Companies


 Q36. Find Max from Stack in O(1) complexityAlgorithm
Ans. Create one extra field called MAX O(1)

when you an element to the stack check these two condition
1. Stack is empty, then MAX = element
2. Stack is not empty then check if the element is greater than MAX then MAX = element


when getMax fuction is called, then return MAX

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

   Like         Discuss         Correct / Improve     complexity  stack  data structure     Asked in 1 Companies


 Q37. How would you implement low latency data structures ?Data Structure
 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     


 Q38. Create a stack of specific size using arrayList?Data Structure
Ans. public class StackUsingArrayList {
   public static void main(String[] args) {
      List list = new ArrayList();
      list.add("A");
      list.add("B");
      list.add("C");
      
      Stack stack = new Stack();

      list.forEach(a -> stack.add(a));
      System.out.println(stack);
   
   }
}

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

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q39. How are hash codes generated ?Data Structure
Ans. Use hashCode() which returns an integer value, generated by a hashing algorithm

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

   Like         Discuss         Correct / Improve     hash codes  hashcode     Asked in 1 Companies


 Q40. Difference between Arrays and LinkedList ?Data Structure
 This question was recently asked at 'Spillman Technologies,Motorola Solutions'.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          Asked in 2 Companies


next 30

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: