1.Easy
Which sorting algorithm chooses a pivot and partitions the array into smaller and larger elements?
- AMerge sort
- BInsertion sort
- CBubble sort
- DQuicksort
2.Easy
What is the Big O of 3n² + 5n + 2?
- AO(n²)
- BO(n³)
- CO(3n²)
- DO(5n)
3.Easy
What is the worst-case time complexity of merge sort?
- AO(n)
- BO(log n)
- CO(n log n)
- DO(n²)
4.Medium
How much stack space does a simple recursive factorial function fact(n) = n × fact(n − 1) use?
- AO(log n)
- BO(n²)
- CO(1)
- DO(n)
5.Medium
How does Prim's algorithm build a minimum spanning tree?
- AIt runs breadth-first search and keeps the BFS tree
- BIt removes the most expensive edge until no cycles remain
- 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
6.Medium
A recurrence T(n) = 2T(n/2) + O(n) solves to:
- AO(n log n)
- BO(log n)
- CO(n)
- DO(n²)
7.Hard
Taking both endpoints of every edge in a maximal matching gives a vertex cover. How good is this cover?
- AOf unknown quality compared to the optimum
- BAlways a minimum vertex cover
- CAt most log n times the minimum
- DAt most twice the size of a minimum vertex cover
8.Hard
The 0/1 knapsack problem solved with dynamic programming takes O(nW) time. Why is this called pseudo-polynomial?
- ABecause n is always small
- BW is a number, so the time is exponential in the number of bits used to write W
- CBecause the algorithm is randomised and its running time varies with each input
- DBecause it only works for W = 0
Answer key
- 1. D · Quicksort
- 2. A · O(n²)
- 3. C · O(n log n)
- 4. D · O(n)
- 5. C · It grows one tree from a start vertex, adding the cheapest edge that leaves the tree
- 6. A · O(n log n)
- 7. D · At most twice the size of a minimum vertex cover
- 8. B · W is a number, so the time is exponential in the number of bits used to write W
Full step-by-step solutions: practise this topic on examproblems.com.