1. Which data structure is used to implement a function call stack?
A) Queue
B) Array
C) Stack
D) Heap
✅ Answer: C) Stack
💡 Explanation: Function calls are managed using a stack (call stack) — the most recent function is resolved first (LIFO).
────────────────────────────────────────────────────────────────────────────────
2. What is the time complexity of accessing an element in an array by index?
A) O(n)
B) O(log n)
C) O(1)
D) O(n²)
✅ Answer: C) O(1)
💡 Explanation: Array access by index is O(1) — constant time — because elements are stored contiguously with direct address calculation.
────────────────────────────────────────────────────────────────────────────────
3. A Binary Search Tree (BST) property requires:
A) All nodes to have equal values
B) Left child < Parent < Right child
C) Parent < Left child < Right child
D) Right child < Parent < Left child
✅ Answer: B) Left child < Parent < Right child
💡 Explanation: In a BST: every node in the left subtree is smaller and every node in the right subtree is larger than the root.
────────────────────────────────────────────────────────────────────────────────
4. Which graph traversal algorithm uses a queue?
A) DFS (Depth First Search)
B) BFS (Breadth First Search)
C) Dijkstra’s Algorithm
D) Topological Sort
✅ Answer: B) BFS (Breadth First Search)
💡 Explanation: BFS uses a queue (FIFO) to explore all neighbors at the current depth before moving to the next level.
────────────────────────────────────────────────────────────────────────────────
5. Dijkstra’s algorithm is used for:
A) Finding the maximum spanning tree
B) Sorting nodes
C) Finding shortest path from a source vertex
D) Graph coloring
✅ Answer: C) Finding shortest path from a source vertex
💡 Explanation: Dijkstra’s algorithm finds the shortest path from a source node to all other nodes in a weighted graph.
────────────────────────────────────────────────────────────────────────────────
6. What is the height of a complete binary tree with n nodes?
A) O(n)
B) O(log n)
C) O(n log n)
D) O(n²)
✅ Answer: B) O(log n)
💡 Explanation: A complete binary tree with n nodes has height ⌊log₂(n)⌋ — O(log n).
────────────────────────────────────────────────────────────────────────────────
7. Hash collision is resolved using:
A) Sorting the hash table
B) Chaining or open addressing
C) Doubling the array size
D) Using a different hash function only
✅ Answer: B) Chaining or open addressing
💡 Explanation: Hash collisions are resolved using chaining (linked list at each bucket) or open addressing (probing for empty slot).
────────────────────────────────────────────────────────────────────────────────
8. Which sorting algorithm is NOT stable?
A) Merge Sort
B) Bubble Sort
C) Quick Sort
D) Insertion Sort
✅ Answer: C) Quick Sort
💡 Explanation: Quick Sort is not stable — equal elements may not maintain their original relative order after sorting.
────────────────────────────────────────────────────────────────────────────────
9. The time complexity of Merge Sort in all cases is:
A) O(n)
B) O(n log n)
C) O(n²)
D) O(log n)
✅ Answer: B) O(n log n)
💡 Explanation: Merge Sort has O(n log n) time complexity in best, worst, and average cases, making it consistent.
────────────────────────────────────────────────────────────────────────────────
10. A trie (prefix tree) is best used for:
A) Sorting integers
B) Storing and searching strings efficiently
C) Graph traversal
D) Priority queues
✅ Answer: B) Storing and searching strings efficiently
💡 Explanation: A trie stores strings character-by-character, enabling fast prefix search, autocomplete, and dictionary operations.
────────────────────────────────────────────────────────────────────────────────
11. In a max-heap, which property must hold?
A) Every parent is smaller than its children
B) Every parent is greater than or equal to its children
C) Tree must be perfectly balanced
D) Leaves must store maximum values
✅ Answer: B) Every parent is greater than or equal to its children
💡 Explanation: In a max-heap, every parent node is greater than or equal to its children, with the maximum at the root.
────────────────────────────────────────────────────────────────────────────────
12. Which algorithm is used for finding Minimum Spanning Tree?
A) Dijkstra’s
B) Bellman-Ford
C) Kruskal’s or Prim’s
D) Floyd-Warshall
✅ Answer: C) Kruskal’s or Prim’s
💡 Explanation: Both Kruskal’s and Prim’s algorithms are used to find the Minimum Spanning Tree of a connected weighted graph.
────────────────────────────────────────────────────────────────────────────────
13. Dynamic programming solves problems by:
A) Divide and conquer without memoization
B) Breaking into overlapping subproblems and storing results to avoid recomputation
C) Using greedy approach
D) Randomly trying all solutions
✅ Answer: B) Breaking into overlapping subproblems and storing results to avoid recomputation
💡 Explanation: Dynamic programming uses memoization or tabulation to store subproblem results and avoid redundant computations.
────────────────────────────────────────────────────────────────────────────────
14. A deque (double-ended queue) allows insertion and deletion:
A) Only at front
B) Only at rear
C) At both front and rear
D) At any position
✅ Answer: C) At both front and rear
💡 Explanation: A deque (double-ended queue) supports insertion and deletion at both the front and rear ends.
────────────────────────────────────────────────────────────────────────────────
15. The worst-case time complexity of Quick Sort is:
A) O(n log n)
B) O(n)
C) O(n²)
D) O(log n)
✅ Answer: C) O(n²)
💡 Explanation: Quick Sort degrades to O(n²) when pivot selection is poor (e.g., always picking the smallest/largest element).
────────────────────────────────────────────────────────────────────────────────
16. What is an adjacency matrix used for?
A) Storing sorted arrays
B) Representing graph connections in a 2D matrix
C) Hash table collision resolution
D) Binary tree traversal
✅ Answer: B) Representing graph connections in a 2D matrix
💡 Explanation: An adjacency matrix is a V×V matrix where matrix[i][j] = 1 if there is an edge between vertices i and j.
────────────────────────────────────────────────────────────────────────────────
17. Floyd-Warshall algorithm is used for:
A) Single-source shortest path
B) Minimum spanning tree
C) All-pairs shortest path
D) Topological sorting
✅ Answer: C) All-pairs shortest path
💡 Explanation: Floyd-Warshall finds shortest paths between ALL pairs of vertices in a weighted graph with O(V³) complexity.
────────────────────────────────────────────────────────────────────────────────
18. Which operation on a linked list is O(1)?
A) Searching for an element
B) Accessing nth element
C) Inserting at the beginning (given head pointer)
D) Sorting
✅ Answer: C) Inserting at the beginning (given head pointer)
💡 Explanation: Inserting at the head of a linked list is O(1) — just update the next pointer and new head reference.
────────────────────────────────────────────────────────────────────────────────
19. Topological sorting is applicable to:
A) Any graph
B) Undirected graphs only
C) Directed Acyclic Graphs (DAG) only
D) Weighted graphs only
✅ Answer: C) Directed Acyclic Graphs (DAG) only
💡 Explanation: Topological sort orders vertices so every directed edge goes from earlier to later vertex — only valid for DAGs.
────────────────────────────────────────────────────────────────────────────────
20. The amortized time complexity for a dynamic array push operation is:
A) O(n)
B) O(n²)
C) O(1)
D) O(log n)
✅ Answer: C) O(1)
💡 Explanation: Dynamic array push is amortized O(1) — most pushes are O(1) and occasional resizing averages out over all operations.
────────────────────────────────────────────────────────────────────────────────