1.Easy
Which of these running times is polynomial?
- AO(nⁿ)
- BO(n³)
- CO(2ⁿ)
- DO(n!)
2.Easy
An O(n²) algorithm takes 1 second for n = 1000. About how long does it take for n = 2000?
- A8 seconds
- B1 second
- C2 seconds
- D4 seconds
3.Easy
Which notation describes a lower bound on growth?
- Ao (little o)
- BΘ (Big Theta)
- CO (Big O)
- DΩ (Big Omega)
4.Medium
How does Prim's algorithm build a minimum spanning tree?
- AIt removes the most expensive edge until no cycles remain
- BIt runs breadth-first search and keeps the BFS tree
- CIt grows one tree from a start vertex, adding the cheapest edge that leaves the tree
- DIt sorts all edges by weight and adds each one unless it would form a cycle in the forest
5.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(mn)
- BO(m + n)
- CO(2m+n)
- DO(mn log n)
6.Medium
What does the recurrence T(n) = T(n − 1) + O(n) solve to?
- AO(n²)
- BO(n log n)
- CO(2ⁿ)
- DO(n)
7.Hard
The 0/1 knapsack problem solved with dynamic programming takes O(nW) time. Why is this called pseudo-polynomial?
- ABecause it only works for W = 0
- BW is a number, so the time is exponential in the number of bits used to write W
- CBecause n is always small
- DBecause the algorithm is randomised and its running time varies with each input
8.Hard
What is the time complexity of: for i = 1 to n: for (j = i; j ≤ n; j = j + i) do O(1) work?
- AO(n)
- BO(n²)
- CO(n log n)
- DO(n √n)
Answer key
- 1. B · O(n³)
- 2. D · 4 seconds
- 3. D · Ω (Big Omega)
- 4. C · It grows one tree from a start vertex, adding the cheapest edge that leaves the tree
- 5. A · O(mn)
- 6. A · O(n²)
- 7. B · W is a number, so the time is exponential in the number of bits used to write W
- 8. C · O(n log n)
Full step-by-step solutions: practise this topic on examproblems.com.