1.Easy
What is the base case of a recursive function?
- AThe call that uses the most memory
- BA case that is answered directly without making another recursive call
- CThe case with the largest input, which is handled before any recursive calls
- DThe first line of the function
2.Easy
An algorithm with two nested loops, each running n times, typically has which complexity?
- AO(log n)
- BO(n)
- CO(n²)
- DO(2n)
3.Easy
What does it mean if an operation runs in O(1) time?
- AIt always takes exactly one second
- BIt can only be run once
- CIts running time does not grow with the input size
- DIt processes exactly one element per second of running time
4.Medium
What is the worst-case time complexity of quicksort?
- AO(log n)
- BO(n log n)
- CO(n)
- DO(n²)
5.Medium
You sort an array of n elements once and then answer k membership queries with binary search. What is the total cost?
- AO(n + k)
- BO(k n log n)
- CO(n log n + k log n)
- DO(nk)
6.Medium
A greedy algorithm:
- AUses only recursion
- BAlways gives the optimal solution
- CMakes the locally best choice at each step
- DTries every possible solution
7.Hard
The halting problem shows that:
- ANo algorithm can decide for every program and input whether it halts
- BLoops should be avoided
- CEvery program eventually halts
- DSome programs run faster on faster computers, so halting depends on hardware
8.Hard
Why is the average lookup in a hash table O(1) but the worst case O(n)?
- AMany keys may collide into the same bucket
- BHash functions are slow
- CArrays have O(n) access
- DKeys must be sorted first
Answer key
- 1. B · A case that is answered directly without making another recursive call
- 2. C · O(n²)
- 3. C · Its running time does not grow with the input size
- 4. D · O(n²)
- 5. C · O(n log n + k log n)
- 6. C · Makes the locally best choice at each step
- 7. A · No algorithm can decide for every program and input whether it halts
- 8. A · Many keys may collide into the same bucket
Full step-by-step solutions: practise this topic on examproblems.com.