1.Easy
Space complexity measures:
- AThe physical size of the computer
- BThe disk space of the program file once it is compiled
- CThe number of lines of code
- DThe amount of memory an algorithm needs as input grows
2.Easy
What is the time complexity of binary search on a sorted array?
- AO(n)
- BO(n log n)
- CO(log n)
- DO(1)
3.Easy
What is the time complexity of linear search in an unsorted array of n elements (worst case)?
- AO(log n)
- BO(1)
- CO(n)
- DO(n²)
4.Medium
A function runs one loop of n iterations and then, separately, another loop of n iterations. What is its time complexity?
- AO(2ⁿ)
- BO(n²)
- CO(n)
- DO(log n)
5.Medium
Dynamic programming is useful when a problem has:
- AOnly random inputs
- BOverlapping subproblems and optimal substructure
- CA single loop
- DNo subproblems at all, so it can be solved in one step
6.Medium
Why do many library sorting routines switch to insertion sort for very small subarrays?
- ARecursive algorithms cannot handle arrays below 10 elements
- BInsertion sort uses less memory than any other sorting algorithm on large inputs
- CInsertion sort is O(n log n) in the worst case
- DInsertion sort has little overhead and is fast on small or nearly sorted inputs
7.Hard
Which statement about little-o notation is correct?
- A2n = o(n), because 2n grows slowly
- Bn = o(n²), but n is not o(n)
- Cn² = o(n)
- Dn = o(n), since every function is little-o of itself
8.Hard
The Held–Karp dynamic programming algorithm solves the travelling salesman problem exactly. What is its running time for n cities?
- AO(n!)
- BO(n³)
- CO(2n²)
- DO(n² 2ⁿ)
Answer key
- 1. D · The amount of memory an algorithm needs as input grows
- 2. C · O(log n)
- 3. C · O(n)
- 4. C · O(n)
- 5. B · Overlapping subproblems and optimal substructure
- 6. D · Insertion sort has little overhead and is fast on small or nearly sorted inputs
- 7. B · n = o(n²), but n is not o(n)
- 8. D · O(n² 2ⁿ)
Full step-by-step solutions: practise this topic on examproblems.com.