1.Easy
An algorithm with two nested loops, each running n times, typically has which complexity?
- AO(2n)
- BO(n)
- CO(log n)
- DO(n²)
2.Easy
What is the time complexity of depth-first search on a graph stored as adjacency lists?
- AO(V × E)
- BO(V²)
- CO(V + E)
- DO(E log V)
3.Easy
What does the worst-case running time of an algorithm describe?
- AThe expected time it takes on a random input of size n
- BThe maximum time it takes over all inputs of size n
- CThe time it takes on the smallest input
- DThe time it takes on a slow computer
4.Medium
What does amortised analysis measure?
- AThe expected cost over random inputs
- BThe cost of an algorithm on the best input
- CThe cost of the single most expensive operation anywhere in the sequence
- DThe average cost per operation over a worst-case sequence of operations
5.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)
6.Medium
What does the recurrence T(n) = T(n − 1) + O(1) solve to?
- AO(2ⁿ)
- BO(log n)
- CO(n²)
- DO(n)
7.Hard
Using the master theorem, T(n) = 8T(n/2) + O(n²) solves to:
- AΘ(n log n)
- BΘ(n³)
- CΘ(n²)
- DΘ(n² log n)
8.Hard
Which statement about P and NP is correct?
- ANP means "not polynomial"
- BEvery problem in P is also in NP
- CNP problems cannot be verified quickly
- DIt has been proven that P ≠ NP
Answer key
- 1. D · O(n²)
- 2. C · O(V + E)
- 3. B · The maximum time it takes over all inputs of size n
- 4. D · The average cost per operation over a worst-case sequence of operations
- 5. C · O(n)
- 6. D · O(n)
- 7. B · Θ(n³)
- 8. B · Every problem in P is also in NP
Full step-by-step solutions: practise this topic on examproblems.com.