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
An algorithm's running time is O(n). What is this growth called?
AConstant
BLogarithmic
CLinear
DQuadratic
2.Easy
What are the three steps of a divide-and-conquer algorithm?
ARead, compute, write
BDivide, conquer, combine
CSort, search, return
DGuess, check, repeat
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
What is the time complexity of the standard dynamic programming algorithm for the longest common subsequence of strings of lengths m and n?
AO(mn)
BO(mn log n)
CO(m + n)
DO(2m+n)
5.Medium
Quicksort always uses the first element as pivot. On which input does it show its worst-case behaviour?
AAn array of length 2
BAn array in random order
CAn array that is already sorted
DAn array whose elements are all different
6.Medium
What is the worst-case time complexity of quicksort?
AO(n)
BO(log n)
CO(n²)
DO(n log n)
7.Hard
Taking both endpoints of every edge in a maximal matching gives a vertex cover. How good is this cover?
AAt most log n times the minimum
BOf unknown quality compared to the optimum
CAt most twice the size of a minimum vertex cover
DAlways a minimum vertex cover
8.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
Answer key
1. C · Linear
2. B · Divide, conquer, combine
3. D · A case that is answered directly without making another recursive call
4. A · O(mn)
5. C · An array that is already sorted
6. C · O(n²)
7. C · At most twice the size of a minimum vertex cover
8. D · O(n) time and O(1) space
Full step-by-step solutions: practise this topic on examproblems.com.