1. Which of the following is a stable sorting algorithm?
A. Quick Sort
B. Merge Sort
C. Heap Sort
D. Selection Sort
Answer: b) Merge Sort
Rationale: Merge Sort is stable because it preserves the relative order of equal
elements.
2. What is the time complexity of accessing an element in an array?
A. O(n)
B. O(log n)
C. O(1)
D. O(n^2)
Answer: c) O(1)
Rationale: Arrays provide constant-time access to elements via indexing.
3. Which data structure is most suitable for implementing a depth-first search (DFS)?
A. Stack
B. Queue
C. Linked List
D. Array
Answer: a) Stack
Rationale: DFS uses a stack to explore nodes, either explicitly or via recursion (which
uses the call stack).
4. Which of the following algorithms has the best average-case time complexity for
sorting?
A. Quick Sort
B. Merge Sort
C. Insertion Sort
D. Bubble Sort
Answer: a) Quick Sort
Rationale: Quick Sort has an average time complexity of O(n log n), making it one of
the fastest in practice.
5. Which of the following is not a type of binary tree?
A. AVL Tree
B. Red-Black Tree
C. B-Tree
D. Complete Binary Tree
Answer: c) B-Tree
Rationale: A B-Tree is a self-balancing tree data structure used primarily for database
indexing and is not a binary tree.
6. What is the time complexity of binary search?
A. O(n)
B. O(log n)
, C. O(n log n)
D. O(1)
Answer: b) O(log n)
Rationale: Binary search divides the search space in half each time, resulting in
logarithmic time complexity.
7. Which of the following is a non-linear data structure?
A. Array
B. Stack
C. Queue
D. Tree
Answer: d) Tree
Rationale: Trees are non-linear structures, while arrays, stacks, and queues are linear.
8. Which algorithm is used to find the shortest path in a graph with non-negative edge
weights?
A. Bellman-Ford
B. Dijkstra's Algorithm
C. Floyd-Warshall
D. Prim’s Algorithm
Answer: b) Dijkstra's Algorithm
Rationale: Dijkstra’s algorithm is used to find the shortest path in graphs with non-
negative edge weights.
9. What is the worst-case time complexity of Quick Sort?
A. O(n log n)
B. O(n^2)
C. O(log n)
D. O(n)
Answer: b) O(n^2)
Rationale: Quick Sort’s worst-case time complexity occurs when the pivot elements are
poorly chosen, leading to unbalanced partitions.
10. In which type of tree is the height of two child subtrees of every node differ by at
most one?
A. AVL Tree
B. Red-Black Tree
C. Binary Search Tree
D. B-Tree
Answer: a) AVL Tree
Rationale: An AVL tree is a self-balancing binary search tree where the height
difference between the left and right subtrees of every node is at most one.
11. Which sorting algorithm has the worst time complexity of O(n^2)?
A. Merge Sort
B. Bubble Sort
C. Heap Sort
D. Quick Sort
Answer: b) Bubble Sort
Rationale: Bubble Sort has a worst-case time complexity of O(n^2) when the input list
A. Quick Sort
B. Merge Sort
C. Heap Sort
D. Selection Sort
Answer: b) Merge Sort
Rationale: Merge Sort is stable because it preserves the relative order of equal
elements.
2. What is the time complexity of accessing an element in an array?
A. O(n)
B. O(log n)
C. O(1)
D. O(n^2)
Answer: c) O(1)
Rationale: Arrays provide constant-time access to elements via indexing.
3. Which data structure is most suitable for implementing a depth-first search (DFS)?
A. Stack
B. Queue
C. Linked List
D. Array
Answer: a) Stack
Rationale: DFS uses a stack to explore nodes, either explicitly or via recursion (which
uses the call stack).
4. Which of the following algorithms has the best average-case time complexity for
sorting?
A. Quick Sort
B. Merge Sort
C. Insertion Sort
D. Bubble Sort
Answer: a) Quick Sort
Rationale: Quick Sort has an average time complexity of O(n log n), making it one of
the fastest in practice.
5. Which of the following is not a type of binary tree?
A. AVL Tree
B. Red-Black Tree
C. B-Tree
D. Complete Binary Tree
Answer: c) B-Tree
Rationale: A B-Tree is a self-balancing tree data structure used primarily for database
indexing and is not a binary tree.
6. What is the time complexity of binary search?
A. O(n)
B. O(log n)
, C. O(n log n)
D. O(1)
Answer: b) O(log n)
Rationale: Binary search divides the search space in half each time, resulting in
logarithmic time complexity.
7. Which of the following is a non-linear data structure?
A. Array
B. Stack
C. Queue
D. Tree
Answer: d) Tree
Rationale: Trees are non-linear structures, while arrays, stacks, and queues are linear.
8. Which algorithm is used to find the shortest path in a graph with non-negative edge
weights?
A. Bellman-Ford
B. Dijkstra's Algorithm
C. Floyd-Warshall
D. Prim’s Algorithm
Answer: b) Dijkstra's Algorithm
Rationale: Dijkstra’s algorithm is used to find the shortest path in graphs with non-
negative edge weights.
9. What is the worst-case time complexity of Quick Sort?
A. O(n log n)
B. O(n^2)
C. O(log n)
D. O(n)
Answer: b) O(n^2)
Rationale: Quick Sort’s worst-case time complexity occurs when the pivot elements are
poorly chosen, leading to unbalanced partitions.
10. In which type of tree is the height of two child subtrees of every node differ by at
most one?
A. AVL Tree
B. Red-Black Tree
C. Binary Search Tree
D. B-Tree
Answer: a) AVL Tree
Rationale: An AVL tree is a self-balancing binary search tree where the height
difference between the left and right subtrees of every node is at most one.
11. Which sorting algorithm has the worst time complexity of O(n^2)?
A. Merge Sort
B. Bubble Sort
C. Heap Sort
D. Quick Sort
Answer: b) Bubble Sort
Rationale: Bubble Sort has a worst-case time complexity of O(n^2) when the input list