1.Easy
What is the base case of a recursive function?
- AThe case with the largest input, which is handled before any recursive calls
- BThe first line of the function
- CA case that is answered directly without making another recursive call
- DThe call that uses the most memory
2.Easy
Accessing an element by index in an array takes:
- AO(1)
- BO(n)
- CO(log n)
- DO(n²)
3.Easy
An algorithm with two nested loops, each running n times, typically has which complexity?
- AO(n)
- BO(n²)
- CO(log n)
- DO(2n)
4.Medium
Why do many library sorting routines switch to insertion sort for very small subarrays?
- AInsertion sort is O(n log n) in the worst case
- BInsertion sort has little overhead and is fast on small or nearly sorted inputs
- CInsertion sort uses less memory than any other sorting algorithm on large inputs
- DRecursive algorithms cannot handle arrays below 10 elements
5.Medium
Dynamic programming is useful when a problem has:
- AA single loop
- BOverlapping subproblems and optimal substructure
- COnly random inputs
- DNo subproblems at all, so it can be solved in one step
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 3 coins; the optimum is 3
- BGreedy uses 4 coins; the optimum is 3
- CGreedy uses 2 coins; the optimum is 2
- DGreedy uses 3 coins; the optimum is 2
7.Hard
The halting problem shows that:
- AEvery program eventually halts
- BSome programs run faster on faster computers, so halting depends on hardware
- CNo algorithm can decide for every program and input whether it halts
- DLoops should be avoided
8.Hard
What is the running time of Dijkstra's algorithm with a binary heap on a graph with V vertices and E edges?
- AO(V³)
- BO((V + E) log V)
- CO(V × E)
- DO(V + E)
Answer key
- 1. C · A case that is answered directly without making another recursive call
- 2. A · O(1)
- 3. B · O(n²)
- 4. B · Insertion sort has little overhead and is fast on small or nearly sorted inputs
- 5. B · Overlapping subproblems and optimal substructure
- 6. D · Greedy uses 3 coins; the optimum is 2
- 7. C · No algorithm can decide for every program and input whether it halts
- 8. B · O((V + E) log V)
Full step-by-step solutions: practise this topic on examproblems.com.