1.Easy
Which of these running times is polynomial?
- AO(n³)
- BO(nⁿ)
- CO(n!)
- DO(2ⁿ)
2.Easy
What is memoisation?
- AFreeing memory after a function returns
- BStoring the results of function calls so repeated calls are answered from memory
- CWriting comments next to each line of code
- DConverting recursion into an equivalent loop automatically so no call stack is needed
3.Easy
Space complexity measures:
- AThe number of lines of code
- BThe disk space of the program file once it is compiled
- CThe physical size of the computer
- DThe amount of memory an algorithm needs as input grows
4.Medium
Which sorting algorithm is stable?
- AMerge sort
- BHeap sort
- CQuicksort (typical in-place version)
- DSelection sort (typical version)
5.Medium
Which statement about a recursive function without a reachable base case is correct?
- AIt keeps calling itself until the call stack overflows
- BIt returns 0 automatically
- CIt runs in O(1) time
- DThe compiler always turns it into a loop that ends safely
6.Medium
What is the time complexity of the standard dynamic programming algorithm for the longest common subsequence of strings of lengths m and n?
- AO(2m+n)
- BO(m + n)
- CO(mn log n)
- DO(mn)
7.Hard
The 0/1 knapsack problem solved with dynamic programming takes O(nW) time. Why is this called pseudo-polynomial?
- AW is a number, so the time is exponential in the number of bits used to write W
- BBecause the algorithm is randomised and its running time varies with each input
- CBecause n is always small
- DBecause it only works for W = 0
8.Hard
Is 22n in O(2ⁿ)?
- ANo, because 22n grows more slowly than 2ⁿ
- BYes, because both are exponential
- CNo, because 22n = 4ⁿ and 4ⁿ / 2ⁿ = 2ⁿ grows without bound
- DYes, because constant factors in the exponent are always ignored in Big O
Answer key
- 1. A · O(n³)
- 2. B · Storing the results of function calls so repeated calls are answered from memory
- 3. D · The amount of memory an algorithm needs as input grows
- 4. A · Merge sort
- 5. A · It keeps calling itself until the call stack overflows
- 6. D · O(mn)
- 7. A · W is a number, so the time is exponential in the number of bits used to write W
- 8. C · No, because 22n = 4ⁿ and 4ⁿ / 2ⁿ = 2ⁿ grows without bound
Full step-by-step solutions: practise this topic on examproblems.com.