1.Easy
A loop starts with i = 1 and doubles i each iteration until i > n. How many iterations does it run?
- AAbout n²
- BAbout n
- CAbout n / 2
- DAbout log₂ n
2.Easy
What does the worst-case running time of an algorithm describe?
- AThe time it takes on the smallest input
- BThe time it takes on a slow computer
- CThe expected time it takes on a random input of size n
- DThe maximum time it takes over all inputs of size n
3.Easy
An O(n²) algorithm takes 1 second for n = 1000. About how long does it take for n = 2000?
- A2 seconds
- B1 second
- C4 seconds
- D8 seconds
4.Medium
What does amortised analysis measure?
- AThe average cost per operation over a worst-case sequence of operations
- BThe expected cost over random inputs
- CThe cost of an algorithm on the best input
- DThe cost of the single most expensive operation anywhere in the sequence
5.Medium
With coins of 1, 3 and 4 and an amount of 6, how many coins does the greedy "largest coin first" method use, compared to the optimum?
- AGreedy uses 2 coins; the optimum is 2
- BGreedy uses 4 coins; the optimum is 3
- CGreedy uses 3 coins; the optimum is 3
- DGreedy uses 3 coins; the optimum is 2
6.Medium
Dynamic programming is useful when a problem has:
- AOnly random inputs
- BOverlapping subproblems and optimal substructure
- CNo subproblems at all, so it can be solved in one step
- DA single loop
7.Hard
How is the travelling salesman problem classified?
- AIt is undecidable
- BIt is in P because Dijkstra's algorithm solves it by visiting every city once
- CThe decision version is in P but the optimisation version is NP-complete
- DThe decision version is NP-complete and the optimisation version is NP-hard
8.Hard
To show that a new problem X is NP-hard, what must you do?
- AShow that X has no polynomial algorithm for small inputs
- BReduce X to a known NP-hard problem in polynomial time
- CReduce a known NP-hard problem to X in polynomial time
- DShow that X can be verified in polynomial time
Answer key
- 1. D · About log₂ n
- 2. D · The maximum time it takes over all inputs of size n
- 3. C · 4 seconds
- 4. A · The average cost per operation over a worst-case sequence of operations
- 5. D · Greedy uses 3 coins; the optimum is 2
- 6. B · Overlapping subproblems and optimal substructure
- 7. D · The decision version is NP-complete and the optimisation version is NP-hard
- 8. C · Reduce a known NP-hard problem to X in polynomial time
Full step-by-step solutions: practise this topic on examproblems.com.