1.Easy
What is the time complexity of binary search on a sorted array?
- AO(n log n)
- BO(n)
- CO(1)
- DO(log n)
2.Easy
Space complexity measures:
- AThe disk space of the program file once it is compiled
- BThe physical size of the computer
- CThe number of lines of code
- DThe amount of memory an algorithm needs as input grows
3.Easy
Which of these grows slowest as n becomes large?
- AO(n²)
- BO(n)
- CO(n log n)
- DO(log n)
4.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 2 coins; the optimum is 2
- CGreedy uses 3 coins; the optimum is 2
- DGreedy uses 3 coins; the optimum is 3
5.Medium
How much stack space does a simple recursive factorial function fact(n) = n × fact(n − 1) use?
- AO(n)
- BO(n²)
- CO(1)
- DO(log n)
6.Medium
What does the recurrence T(n) = T(n/2) + O(1) solve to?
- AO(n log n)
- BO(n)
- CO(log n)
- DO(1)
7.Hard
What are the time and space costs of computing the n-th Fibonacci number with a loop that keeps only the last two values?
- AO(log n) time and O(n) space
- BO(n) time and O(n) space
- CO(2ⁿ) time and O(1) space
- DO(n) time and O(1) space
8.Hard
What would follow if someone found a polynomial-time algorithm for one NP-complete problem?
- AThe halting problem would become decidable
- BAll exponential-time algorithms would immediately run in linear time
- CEvery problem in NP could be solved in polynomial time, so P = NP
- DOnly that one problem would move into P
Answer key
- 1. D · O(log n)
- 2. D · The amount of memory an algorithm needs as input grows
- 3. D · O(log n)
- 4. C · Greedy uses 3 coins; the optimum is 2
- 5. A · O(n)
- 6. C · O(log n)
- 7. D · O(n) time and O(1) space
- 8. C · Every problem in NP could be solved in polynomial time, so P = NP
Full step-by-step solutions: practise this topic on examproblems.com.