1.Which of the following data structures uses LIFO (Last In First Out) order?
ANS :(b) A stack uses LIFO (Last In First Out) order.
2. What is the time complexity of accessing an element in an array?
ANS : (c) The time complexity of accessing an element in an array is O(1).
3. Which of the following is not a linear data structure?
ANS :(d) A tree is not a linear data structure; it is a hierarchical data structure.
4. In a binary tree, the maximum number of nodes at level 'l' is:
ANS : (a) The maximum number of nodes at level 'l' in a binary tree is 2^l.
5. Which of the following data structures is used for implementing recursion?
ANS : (b) A stack is used for implementing recursion.
6. What is the worst-case time complexity of searching for an element in a balanced binary search tree?
ANS :(b) The worst-case time complexity of searching for an element in a balanced binary search tree is O(log n).
7. Which of the following is a characteristic of a queue?
ANS :(b) In a queue, elements are added at the rear and removed from the front.
8. In a doubly linked list, each node contains:
ANS : (a) In a doubly linked list, each node contains data, a pointer to the next node, and a pointer to the previous node.
9. Which of the following sorting algorithms has the best average-case time complexity?
ANS :(c) Quick Sort has the best average-case time complexity of O(n log n).
10. What is the primary purpose of a hash table?
ANS :(b) The primary purpose of a hash table is to allow fast access to data.
11. Which of the following is a characteristic of a binary search tree?
ANS : (a)(a) Each node in a binary search tree has at most two children.
12. What is the time complexity of inserting an element in a linked list?
ANS :(a) The time complexity of inserting an element in a linked list is O(1) if you insert at the head.
13. Which of the following data structures is used to implement a priority queue?
ANS : (c) A heap is commonly used to implement a priority queue.
14. What is the space complexity of a binary tree with 'n' nodes?
ANS :(a) The space complexity of a binary tree with 'n' nodes is O(n).
15. Which of the following is true about a circular linked list?
ANS :(a) In a circular linked list, the last node points to the first node.
16. Which of the following algorithms is used for finding the shortest path in a graph?
ANS :(b) Dijkstra's Algorithm is used for finding the shortest path in a graph.
17. In a max heap, the value of each node is:
ANS :(b) In a max heap, the value of each node is greater than or equal to the values of its children.
18. Which of the following is not a characteristic of a stack?
ANS :(a) A stack follows the FIFO principle.
19. What is the time complexity of deleting an element from a binary search tree?
ANS : (a) the time complexity for deleting an element from a BST is O(log n) on average for balanced trees and O(n) in the worst case for unbalanced trees.
20. Which of the following is a disadvantage of using a linked list?
ANS : (c) Random access is a disadvantage of linked lists because accessing an element requires traversing the list from the head, making it slower than array indexing.
21. Which data structure is used to convert infix to postfix expression?
ANS : (c) Stack is used for converting infix expressions to postfix using operator precedence rules.
22. What is the worst-case time complexity of linear search?
ANS : (a) In the worst case, linear search needs to check every element, resulting in O(n) time.
23. Which data structure allows insertion and deletion at both ends?
ANS : (c) A Deque (Double Ended Queue) allows both insertion and deletion from front and rear.
24. What is the height of a binary tree with a single node?
ANS : (a) A tree with only the root node has a height of 0.
25. Which traversal is used to get the prefix expression of an expression tree?
ANS : (a) Preorder traversal gives the prefix form of an expression tree.
26. What does DFS stand for in graph algorithms?
ANS : (b) DFS stands for Depth First Search.
27. Which sorting algorithm is considered the fastest in practice for average cases?
ANS : (c) Quick Sort is often the fastest on average for large datasets.
28. What does the term ‘overflow’ refer to in data structures?
ANS : (c) Overflow occurs when attempting to insert into a full stack.
29. What is the auxiliary space complexity of merge sort?
ANS : (b) Merge sort requires O(n) auxiliary space for merging.
30. Which data structure is typically used for implementing undo functionality?
ANS : (c) Stack allows tracking of the last performed operation, useful in undo mechanisms.
31. What is the time complexity of accessing an element in a hash table?
ANS : (b) Hash tables provide O(1) average time complexity for access using hash functions.
32. Which data structure is used for implementing recursion internally?
ANS : (b) The call stack is used to manage function calls during recursion.
33. Which traversal method is used for breadth-first traversal in a tree?
ANS : (c) Breadth-first traversal is achieved using level order traversal, typically with a queue.
34. In which case will a binary search be most efficient?
ANS : (b) Binary search works only on sorted arrays or lists.
35. Which data structure is used in Dijkstra’s shortest path algorithm?
ANS : (c) Priority Queue is used to select the next closest vertex in Dijkstra’s algorithm.
36. Which algorithm technique does Merge Sort follow?
ANS : (c) Merge Sort divides the array and conquers with merge steps.
37. What is the maximum number of nodes in a binary tree of height h?
ANS : (a) The maximum number of nodes is 2h+1 - 1 in a binary tree.
38. Which of the following data structures can be used to detect a cycle in a graph?
ANS : (c) Disjoint Set Union (Union-Find) is used to detect cycles in graphs.
39. What is the in-order traversal of a binary search tree?
ANS : (b) In-order traversal of BST gives nodes in sorted order.
40. Which of the following is true for a queue?
ANS : (a) Queue follows FIFO – the first element inserted is the first to be removed.
41. Which data structure is best suited for implementing LRU cache?
ANS : (b) LRU cache is efficiently implemented using HashMap and Doubly Linked List.
42. What is the height of an empty tree?
ANS : (c) By convention, the height of an empty tree is -1.
43. Which sorting algorithm is best suited for nearly sorted arrays?
ANS : (a) Insertion Sort is efficient for nearly sorted data with time complexity approaching O(n).
44. What is the worst-case time complexity of Quick Sort?
ANS : (c) Quick Sort has a worst-case time of O(n²) when the pivot elements are poorly chosen.
45. What does FIFO stand for in data structures?
ANS : (c) FIFO means the first element inserted is the first one to be removed, typical of queues.
46. Which of the following is not a linear data structure?
ANS : (d) Tree is a non-linear hierarchical data structure.
47. Which traversal technique is used in depth-first search of a graph?
ANS : (c) DFS uses stack-based traversal like recursive preorder.
48. Which data structure allows constant time insertion and deletion at both ends?
ANS : (d) Deque (double-ended queue) allows O(1) insertion/deletion at both ends.
49. What is the time complexity of inserting an element in a heap?
ANS : (b) Inserting into a heap takes O(log n) due to the need to restore the heap property.
50. Which data structure is best suited for implementing undo functionality?
ANS : (a) Stack is ideal for undo functionality because it supports LIFO behavior.