1.Easy
What is the base case of a recursive function?
- AThe call that uses the most memory
- BA case that is answered directly without making another recursive call
- CThe case with the largest input, which is handled before any recursive calls
- DThe first line of the function
2.Easy
What is an algorithm?
- AA data structure that stores numbers
- BAny computer program that has a graphical interface
- CA finite sequence of well-defined steps that solves a problem
- DA programming language designed for writing mathematical formulas
3.Easy
What is the worst-case time complexity of insertion sort?
- AO(n²)
- BO(log n)
- CO(n log n)
- DO(n)
4.Medium
Which statement about a recursive function without a reachable base case is correct?
- AIt runs in O(1) time
- BIt keeps calling itself until the call stack overflows
- CIt returns 0 automatically
- DThe compiler always turns it into a loop that ends safely
5.Medium
What is the time complexity of the Bellman–Ford algorithm on a graph with V vertices and E edges?
- AO(E log V)
- BO(V × E)
- CO(V + E)
- DO(V³ × E)
6.Medium
In the activity selection problem, which greedy rule always gives a maximum number of non-overlapping activities?
- APick the shortest activity first
- BPick the activity with the fewest overlaps first, then repeat with the compatible ones
- CPick the activity that starts earliest
- DPick the activity that finishes earliest, then repeat with the compatible ones
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(n) time and O(n) space
- BO(2ⁿ) time and O(1) space
- CO(log n) time and O(n) space
- DO(n) time and O(1) space
8.Hard
Which technique gives an expected O(n log n) running time for quicksort on any input?
- AChoosing the pivot uniformly at random
- BAlways choosing the first element
- CSorting the input before running quicksort
- DUsing recursion only on the left side
Answer key
- 1. B · A case that is answered directly without making another recursive call
- 2. C · A finite sequence of well-defined steps that solves a problem
- 3. A · O(n²)
- 4. B · It keeps calling itself until the call stack overflows
- 5. B · O(V × E)
- 6. D · Pick the activity that finishes earliest, then repeat with the compatible ones
- 7. D · O(n) time and O(1) space
- 8. A · Choosing the pivot uniformly at random
Full step-by-step solutions: practise this topic on examproblems.com.