1.Easy
What is the time complexity of binary search on a sorted array?
- AO(log n)
- BO(n)
- CO(n log n)
- DO(1)
2.Easy
What does the average-case running time describe?
- AThe time for an input of average length
- BThe time on the most common computer
- CThe middle value between the best-case and worst-case running times
- DThe expected time over a given distribution of inputs of size n
3.Easy
An O(n) algorithm takes 3 seconds for n = 1 million. About how long does it take for n = 2 million?
- A6 seconds
- B12 seconds
- C3 seconds
- D9 seconds
4.Medium
What does the recurrence T(n) = 2T(n − 1) + O(1) solve to?
- AO(n log n)
- BO(n)
- CO(n²)
- DO(2ⁿ)
5.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 4 coins; the optimum is 3
- BGreedy uses 3 coins; the optimum is 3
- CGreedy uses 3 coins; the optimum is 2
- DGreedy uses 2 coins; the optimum is 2
6.Medium
In a sorted array, you look for two elements that sum to a target by moving one pointer from each end inwards. What is the time complexity?
- AO(n)
- BO(n²)
- CO(log n)
- DO(n log n)
7.Hard
Which two things must be shown to prove that a decision problem X is NP-complete?
- AX has no polynomial algorithm, and X is decidable
- BX is in P, and X reduces to SAT
- CX reduces to a problem in P, and X is in NP
- DX is in NP, and a known NP-complete problem reduces to X in polynomial time
8.Hard
What is the time complexity of building a binary heap from n unsorted elements with the bottom-up method?
- AO(n)
- BO(n²)
- CO(log n)
- DO(n log n)
Answer key
- 1. A · O(log n)
- 2. D · The expected time over a given distribution of inputs of size n
- 3. A · 6 seconds
- 4. D · O(2ⁿ)
- 5. C · Greedy uses 3 coins; the optimum is 2
- 6. A · O(n)
- 7. D · X is in NP, and a known NP-complete problem reduces to X in polynomial time
- 8. A · O(n)
Full step-by-step solutions: practise this topic on examproblems.com.