Algorithms Quiz (30 Questions)
1. 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
Explanation: Binary search halves the search space each time, so it takes log₂(n) steps.
2. Which algorithm is not comparison-based?
A) Merge Sort
B) Heap Sort
C) Quick Sort
D) Counting Sort
Answer: D
Explanation: Counting Sort uses keys as indexes, not comparisons between elements.
3. What is the best case time complexity of Quick Sort?
A) O(n²)
B) O(n)
C) O(n log n)
D) O(log n)
Answer: C
Explanation: In the best case, the pivot divides the array evenly each time.
4. Which data structure is used in Breadth-First Search (BFS)?
A) Stack
B) Queue
C) Priority Queue
D) Hash Map
Answer: B
Explanation: BFS explores neighbors level by level using a queue.
, 5. What is dynamic programming mainly used for?
A) Real-time systems
B) Randomization
C) Optimal substructure problems
D) Memory management
Answer: C
Explanation: DP solves problems by combining solutions to subproblems.
6. What does Big O notation represent?
A) Average runtime
B) Worst-case scenario
C) Best-case scenario
D) Input size
Answer: B
Explanation: Big O describes the upper bound on runtime complexity.
7. What is the purpose of memoization?
A) Minimize disk usage
B) Reduce code size
C) Optimize recursive calls
D) Avoid network calls
Answer: C
Explanation: Memoization caches results to avoid redundant computations.
8. Dijkstra’s algorithm doesn’t work with graphs containing:
A) Loops
B) Zero-weight edges
C) Negative-weight edges
D) Undirected edges
Answer: C
Explanation: Dijkstra’s assumes once a node is visited, it has the shortest path.
1. 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
Explanation: Binary search halves the search space each time, so it takes log₂(n) steps.
2. Which algorithm is not comparison-based?
A) Merge Sort
B) Heap Sort
C) Quick Sort
D) Counting Sort
Answer: D
Explanation: Counting Sort uses keys as indexes, not comparisons between elements.
3. What is the best case time complexity of Quick Sort?
A) O(n²)
B) O(n)
C) O(n log n)
D) O(log n)
Answer: C
Explanation: In the best case, the pivot divides the array evenly each time.
4. Which data structure is used in Breadth-First Search (BFS)?
A) Stack
B) Queue
C) Priority Queue
D) Hash Map
Answer: B
Explanation: BFS explores neighbors level by level using a queue.
, 5. What is dynamic programming mainly used for?
A) Real-time systems
B) Randomization
C) Optimal substructure problems
D) Memory management
Answer: C
Explanation: DP solves problems by combining solutions to subproblems.
6. What does Big O notation represent?
A) Average runtime
B) Worst-case scenario
C) Best-case scenario
D) Input size
Answer: B
Explanation: Big O describes the upper bound on runtime complexity.
7. What is the purpose of memoization?
A) Minimize disk usage
B) Reduce code size
C) Optimize recursive calls
D) Avoid network calls
Answer: C
Explanation: Memoization caches results to avoid redundant computations.
8. Dijkstra’s algorithm doesn’t work with graphs containing:
A) Loops
B) Zero-weight edges
C) Negative-weight edges
D) Undirected edges
Answer: C
Explanation: Dijkstra’s assumes once a node is visited, it has the shortest path.