1.Easy
What is the time complexity of binary search on a sorted array?
- AO(n)
- BO(1)
- CO(log n)
- DO(n log n)
2.Easy
A problem is usually called tractable if:
- AIt has no solution
- BIt can be solved in constant time
- CIt can only be solved by trying every possibility
- DIt can be solved in polynomial time
3.Easy
Space complexity measures:
- AThe number of lines of code
- BThe amount of memory an algorithm needs as input grows
- CThe disk space of the program file once it is compiled
- DThe physical size of the computer
4.Medium
A function runs one loop of n iterations and then, separately, another loop of n iterations. What is its time complexity?
- AO(n)
- BO(2ⁿ)
- CO(n²)
- DO(log n)
5.Medium
What does the recurrence T(n) = T(n − 1) + O(1) solve to?
- AO(log n)
- BO(2ⁿ)
- CO(n)
- DO(n²)
6.Medium
How does Prim's algorithm build a minimum spanning tree?
- AIt removes the most expensive edge until no cycles remain
- BIt grows one tree from a start vertex, adding the cheapest edge that leaves the tree
- CIt runs breadth-first search and keeps the BFS tree
- DIt sorts all edges by weight and adds each one unless it would form a cycle in the forest
7.Hard
Taking both endpoints of every edge in a maximal matching gives a vertex cover. How good is this cover?
- AAt most twice the size of a minimum vertex cover
- BAlways a minimum vertex cover
- COf unknown quality compared to the optimum
- DAt most log n times the minimum
8.Hard
Which two things must be shown to prove that a decision problem X is NP-complete?
- AX reduces to a problem in P, and X is in NP
- BX has no polynomial algorithm, and X is decidable
- CX is in NP, and a known NP-complete problem reduces to X in polynomial time
- DX is in P, and X reduces to SAT
Answer key
- 1. C · O(log n)
- 2. D · It can be solved in polynomial time
- 3. B · The amount of memory an algorithm needs as input grows
- 4. A · O(n)
- 5. C · O(n)
- 6. B · It grows one tree from a start vertex, adding the cheapest edge that leaves the tree
- 7. A · At most twice the size of a minimum vertex cover
- 8. C · X is in NP, and a known NP-complete problem reduces to X in polynomial time
Full step-by-step solutions: practise this topic on examproblems.com.