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
Space complexity measures:
AThe amount of memory an algorithm needs as input grows
BThe number of lines of code
CThe disk space of the program file once it is compiled
DThe physical size of the computer
2.Easy
What does f(n) = Θ(g(n)) mean?
Af grows strictly faster than g
Bf is always smaller than g for every n, so g bounds it from above but never from below
Cf grows strictly slower than g
Df grows at the same rate as g, bounded above and below by constant multiples of g
3.Easy
What are the three steps of a divide-and-conquer algorithm?
ADivide, conquer, combine
BGuess, check, repeat
CRead, compute, write
DSort, search, return
4.Medium
What is the time complexity of: for i = 1 to n: (j = 1; while j < n: j = j × 2)?
AO(n log n)
BO(log n)
CO(n²)
DO(n)
5.Medium
Why does dynamic programming give no real speed-up for merge sort?
ADynamic programming only works on graph problems, not on arrays
BIts subproblems do not overlap, so there is nothing to reuse
CMerge sort has no recursive structure
DMerge sort is already O(n)
6.Medium
Why is the base of a logarithm usually left out in Big O, as in O(log n)?
ALogarithms are always rounded to integers
BAll logarithms in computer science have base 10, so it is implied
CLogarithms with different bases differ only by a constant factor
DThe base only matters for small n
7.Hard
Karatsuba multiplication satisfies T(n) = 3T(n/2) + O(n). What does this solve to?
AΘ(nlog₂ 3), about n1.585
BΘ(n3)
CΘ(n log n)
DΘ(n²)
8.Hard
Insertion sort runs in O(n) on sorted input. Does this contradict the Ω(n log n) lower bound for comparison sorting?
ANo, because insertion sort is not a comparison sort
BYes, the lower bound is therefore wrong
CNo, the lower bound applies to the worst case over all inputs, not to every input
DYes, but only for arrays shorter than 100
Answer key
1. A · The amount of memory an algorithm needs as input grows
2. D · f grows at the same rate as g, bounded above and below by constant multiples of g
3. A · Divide, conquer, combine
4. A · O(n log n)
5. B · Its subproblems do not overlap, so there is nothing to reuse
6. C · Logarithms with different bases differ only by a constant factor
7. A · Θ(nlog₂ 3), about n1.585
8. C · No, the lower bound applies to the worst case over all inputs, not to every input
Full step-by-step solutions: practise this topic on examproblems.com.