1.Easy
How does selection sort work?
- AIt inserts each element into a growing sorted part by shifting
- BIt repeatedly swaps neighbouring elements that are in the wrong order
- CIt splits the array in halves and merges them
- DIt repeatedly finds the minimum of the unsorted part and swaps it to the front
2.Easy
What does it mean if an operation runs in O(1) time?
- AIt processes exactly one element per second of running time
- BIts running time does not grow with the input size
- CIt always takes exactly one second
- DIt can only be run once
3.Easy
What is memoisation?
- AConverting recursion into an equivalent loop automatically so no call stack is needed
- BFreeing memory after a function returns
- CStoring the results of function calls so repeated calls are answered from memory
- DWriting comments next to each line of code
4.Medium
What is the time complexity of: for i = 1 to n: (j = 1; while j < n: j = j × 2)?
- AO(n log n)
- BO(n)
- CO(log n)
- DO(n²)
5.Medium
How much stack space does a simple recursive factorial function fact(n) = n × fact(n − 1) use?
- AO(log n)
- BO(n)
- CO(1)
- DO(n²)
6.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 2
- DGreedy uses 3 coins; the optimum is 3
7.Hard
Which algorithm finds a minimum spanning tree by repeatedly adding the cheapest edge that does not form a cycle?
- APrim's algorithm starting from one node
- BDijkstra's algorithm
- CFloyd–Warshall
- DKruskal's algorithm
8.Hard
Is 22n in O(2ⁿ)?
- ANo, because 22n grows more slowly than 2ⁿ
- BYes, because both are exponential
- CYes, because constant factors in the exponent are always ignored in Big O
- DNo, because 22n = 4ⁿ and 4ⁿ / 2ⁿ = 2ⁿ grows without bound
Answer key
- 1. D · It repeatedly finds the minimum of the unsorted part and swaps it to the front
- 2. B · Its running time does not grow with the input size
- 3. C · Storing the results of function calls so repeated calls are answered from memory
- 4. A · O(n log n)
- 5. B · O(n)
- 6. C · Greedy uses 3 coins; the optimum is 2
- 7. D · Kruskal's algorithm
- 8. D · No, because 22n = 4ⁿ and 4ⁿ / 2ⁿ = 2ⁿ grows without bound
Full step-by-step solutions: practise this topic on examproblems.com.