1.Easy
Which sorting algorithm repeatedly swaps adjacent elements that are in the wrong order?
- AHeap sort
- BQuicksort
- CMerge sort
- DBubble sort
2.Easy
What is the base case of a recursive function?
- AThe first line of the function
- BThe case with the largest input, which is handled before any recursive calls
- CThe call that uses the most memory
- DA case that is answered directly without making another recursive call
3.Easy
What is the running time of counting sort for n integers in the range 0 to k?
- AO(n log n)
- BO(k log n)
- CO(n + k)
- DO(n²)
4.Medium
What does it mean that a problem has optimal substructure?
- AThe problem has exactly one optimal solution, which every subproblem shares
- BEvery subproblem has the same size
- CThe problem can be solved in constant time
- DAn optimal solution can be built from optimal solutions of its subproblems
5.Medium
Breadth-first search on an unweighted graph finds:
- AA topological order in all graphs
- BThe minimum spanning tree
- CShortest paths in number of edges from the start node
- DShortest paths in graphs that contain negative edge weights
6.Medium
What does the recurrence T(n) = T(n − 1) + O(1) solve to?
- AO(n²)
- BO(log n)
- CO(2ⁿ)
- DO(n)
7.Hard
What would follow if someone found a polynomial-time algorithm for one NP-complete problem?
- AEvery problem in NP could be solved in polynomial time, so P = NP
- BAll exponential-time algorithms would immediately run in linear time
- CThe halting problem would become decidable
- DOnly that one problem would move into P
8.Hard
What is the amortised cost of incrementing a binary counter, given that one increment may flip many bits?
- AO(n) per increment
- BO(n log n) per increment
- CO(1) per increment
- DO(log n) per increment
Answer key
- 1. D · Bubble sort
- 2. D · A case that is answered directly without making another recursive call
- 3. C · O(n + k)
- 4. D · An optimal solution can be built from optimal solutions of its subproblems
- 5. C · Shortest paths in number of edges from the start node
- 6. D · O(n)
- 7. A · Every problem in NP could be solved in polynomial time, so P = NP
- 8. C · O(1) per increment
Full step-by-step solutions: practise this topic on examproblems.com.