1.Easy
What is the worst-case time complexity of insertion sort?
- AO(n²)
- BO(n log n)
- CO(log n)
- DO(n)
2.Easy
What is recursion?
- AA loop that never ends
- BA sorting method
- CA function that calls itself on smaller inputs
- DA type of data structure
3.Easy
What is the base case of a recursive function?
- AThe call that uses the most memory
- BThe first line of the function
- CThe case with the largest input, which is handled before any recursive calls
- DA case that is answered directly without making another recursive call
4.Medium
Why do many library sorting routines switch to insertion sort for very small subarrays?
- AInsertion sort uses less memory than any other sorting algorithm on large inputs
- BInsertion sort has little overhead and is fast on small or nearly sorted inputs
- CInsertion sort is O(n log n) in the worst case
- DRecursive algorithms cannot handle arrays below 10 elements
5.Medium
What is the time complexity of: for i = 1 to n: (j = 1; while j < n: j = j × 2)?
- AO(n)
- BO(n log n)
- CO(n²)
- DO(log n)
6.Medium
What does it mean that a problem has optimal substructure?
- AThe problem has exactly one optimal solution, which every subproblem shares
- BEvery subproblem has the same size
- CThe problem can be solved in constant time
- DAn optimal solution can be built from optimal solutions of its subproblems
7.Hard
The Held–Karp dynamic programming algorithm solves the travelling salesman problem exactly. What is its running time for n cities?
- AO(n² 2ⁿ)
- BO(2n²)
- CO(n³)
- DO(n!)
8.Hard
Which definition of the class NP is correct?
- AProblems that are not polynomial
- BDecision problems whose yes-answers can be verified in polynomial time given a certificate
- CProblems that cannot be solved in polynomial time
- DProblems that no algorithm can solve
Answer key
- 1. A · O(n²)
- 2. C · A function that calls itself on smaller inputs
- 3. D · A case that is answered directly without making another recursive call
- 4. B · Insertion sort has little overhead and is fast on small or nearly sorted inputs
- 5. B · O(n log n)
- 6. D · An optimal solution can be built from optimal solutions of its subproblems
- 7. A · O(n² 2ⁿ)
- 8. B · Decision problems whose yes-answers can be verified in polynomial time given a certificate
Full step-by-step solutions: practise this topic on examproblems.com.