Algorithms & Complexity Quiz
Grade 12 · Technology · Quiz
Challenge your understanding of Big O analysis, algorithm design paradigms, and computational complexity theory.
Questions
Binary search on a sorted array of 1,024 elements requires at most how many comparisons?
- 10
- 32
- 512
- 1024
Show answer
Answer: 10
Binary search halves the search space each step; log₂(1024) = 10, so at most 10 comparisons are needed.
Which of the following algorithms is NOT an example of the dynamic programming paradigm?
- Longest Common Subsequence
- 0/1 Knapsack
- Dijkstra's Shortest Path
- Floyd-Warshall All-Pairs Shortest Path
Show answer
Answer: Dijkstra's Shortest Path
Dijkstra's is a greedy algorithm, not DP. LCS, 0/1 Knapsack, and Floyd-Warshall all use DP tables to store subproblem results.
Every NP-complete problem can currently be solved in polynomial time.
Show answer
Answer: False
No polynomial-time algorithm is known for any NP-complete problem. Whether one exists is the unsolved P vs NP question.
What does it mean for an algorithm to have O(1) space complexity?
- It uses no memory at all
- Its memory usage is constant regardless of input size
- It runs in constant time
- It uses memory proportional to the square of the input
Show answer
Answer: Its memory usage is constant regardless of input size
O(1) space means the algorithm uses a fixed amount of extra memory regardless of input size — for example, an in-place swap.
An algorithm that solves a problem by making the locally optimal choice at each step, without reconsidering past choices, is called a ______ algorithm.
Show answer
Answer: greedy
Greedy algorithms commit to a local optimum at each step without backtracking; they work when the problem has the greedy-choice property.
Which recurrence relation correctly describes the time complexity of merge sort?
- T(n) = T(n-1) + O(1)
- T(n) = 2T(n/2) + O(n)
- T(n) = T(n/2) + O(1)
- T(n) = 2T(n-1) + O(n)
Show answer
Answer: T(n) = 2T(n/2) + O(n)
Merge sort divides into 2 halves (2T(n/2)) and merges in linear time (O(n)), giving T(n) = 2T(n/2) + O(n), which resolves to O(n log n).
Backtracking algorithms always explore every possible candidate solution before returning an answer.
Show answer
Answer: False
Backtracking prunes branches early when a constraint is violated, avoiding exploration of invalid candidates — this is what makes it more efficient than brute force.
Which statement about NP-hard problems is correct?
- All NP-hard problems are in NP
- NP-hard problems cannot be approximated
- Solving one NP-hard problem in polynomial time would imply P = NP
- NP-hard problems have no known algorithms
Show answer
Answer: Solving one NP-hard problem in polynomial time would imply P = NP
NP-hard problems are at least as hard as any NP problem; solving one in polynomial time would prove P = NP. Not all NP-hard problems are in NP (some are undecidable).
Get a personalized course on Algorithms & Complexity built around your child.