For teachers: free to print, copy and use in class. Every new worksheet has new values and its own answer key. A link to ExamProblems on your course page is appreciated.
Name: ____________________ Date: ____________
1.Easy
What is memoisation?
AFreeing memory after a function returns
BConverting recursion into an equivalent loop automatically so no call stack is needed
CWriting comments next to each line of code
DStoring the results of function calls so repeated calls are answered from memory
2.Easy
A problem is usually called tractable if:
AIt has no solution
BIt can be solved in polynomial time
CIt can be solved in constant time
DIt can only be solved by trying every possibility
3.Easy
What is the base case of a recursive function?
AThe case with the largest input, which is handled before any recursive calls
BThe call that uses the most memory
CThe first line of the function
DA case that is answered directly without making another recursive call
4.Medium
Why does dynamic programming give no real speed-up for merge sort?
AIts subproblems do not overlap, so there is nothing to reuse
BMerge sort has no recursive structure
CDynamic programming only works on graph problems, not on arrays
DMerge sort is already O(n)
5.Medium
What is the amortised time complexity of appending to a dynamic array that doubles its capacity when full?
AO(1)
BO(n²)
CO(n)
DO(log n)
6.Medium
The time complexity of naive recursive Fibonacci (fib(n) = fib(n−1) + fib(n−2)) is:
ALogarithmic
BExponential
CLinear
DConstant
7.Hard
For which knapsack variant does the greedy rule "take items in order of value per weight" always give an optimal answer?
AThe 0/1 knapsack, where items must always be taken whole
BBoth variants
CThe fractional knapsack, where items may be split
DNeither variant
8.Hard
Which statement about P and NP is correct?
AIt has been proven that P ≠ NP
BNP means "not polynomial"
CEvery problem in P is also in NP
DNP problems cannot be verified quickly
Answer key
1. D · Storing the results of function calls so repeated calls are answered from memory
2. B · It can be solved in polynomial time
3. D · A case that is answered directly without making another recursive call
4. A · Its subproblems do not overlap, so there is nothing to reuse
5. A · O(1)
6. B · Exponential
7. C · The fractional knapsack, where items may be split
8. C · Every problem in P is also in NP
Full step-by-step solutions: practise this topic on examproblems.com.