Algorithms & complexity worksheet with answers

Free printable Algorithms & complexity worksheet: 8 problems from easy to exam level, with an answer key. Print it or save it as a PDF.

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

Which of these running times is polynomial?

  1. AO(n!)
  2. BO(2ⁿ)
  3. CO(n³)
  4. DO(nⁿ)
2.Easy

How much extra memory does a standard array-based merge sort use?

  1. AO(log n)
  2. BO(n²)
  3. CO(1)
  4. DO(n)
3.Easy

What does f(n) = Θ(g(n)) mean?

  1. Af is always smaller than g for every n, so g bounds it from above but never from below
  2. Bf grows at the same rate as g, bounded above and below by constant multiples of g
  3. Cf grows strictly faster than g
  4. Df grows strictly slower than g
4.Medium

What does the recurrence T(n) = T(n − 1) + O(n) solve to?

  1. AO(n log n)
  2. BO(n)
  3. CO(2ⁿ)
  4. DO(n²)
5.Medium

Why is the base of a logarithm usually left out in Big O, as in O(log n)?

  1. ALogarithms with different bases differ only by a constant factor
  2. BThe base only matters for small n
  3. CAll logarithms in computer science have base 10, so it is implied
  4. DLogarithms are always rounded to integers
6.Medium

What does the recurrence T(n) = 2T(n − 1) + O(1) solve to?

  1. AO(n log n)
  2. BO(n)
  3. CO(n²)
  4. DO(2ⁿ)
7.Hard

Topological sorting is possible only for:

  1. AComplete graphs
  2. BUndirected graphs
  3. CDirected acyclic graphs
  4. DGraphs with negative weights
8.Hard

Strassen's algorithm multiplies matrices using 7 instead of 8 recursive multiplications of half-size blocks. What is its running time?

  1. AΘ(n³)
  2. BΘ(n2)
  3. CΘ(n² log n)
  4. DΘ(nlog₂ 7), about n2.81

Answer key

  1. 1. C · O(n³)
  2. 2. D · O(n)
  3. 3. B · f grows at the same rate as g, bounded above and below by constant multiples of g
  4. 4. D · O(n²)
  5. 5. A · Logarithms with different bases differ only by a constant factor
  6. 6. D · O(2ⁿ)
  7. 7. C · Directed acyclic graphs
  8. 8. D · Θ(nlog₂ 7), about n2.81

Full step-by-step solutions: practise this topic on examproblems.com.