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 notation describes a lower bound on growth?

  1. Ao (little o)
  2. BO (Big O)
  3. CΘ (Big Theta)
  4. DΩ (Big Omega)
2.Easy

What is the time complexity of binary search on a sorted array?

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

Which notation describes an upper bound on growth?

  1. ALittle omega
  2. BBig O
  3. CBig Omega
  4. DBig Theta
4.Medium

Quicksort always uses the first element as pivot. On which input does it show its worst-case behaviour?

  1. AAn array in random order
  2. BAn array whose elements are all different
  3. CAn array that is already sorted
  4. DAn array of length 2
5.Medium

Why do many library sorting routines switch to insertion sort for very small subarrays?

  1. AInsertion sort is O(n log n) in the worst case
  2. BRecursive algorithms cannot handle arrays below 10 elements
  3. CInsertion sort has little overhead and is fast on small or nearly sorted inputs
  4. DInsertion sort uses less memory than any other sorting algorithm on large inputs
6.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. BLogarithms are always rounded to integers
  3. CAll logarithms in computer science have base 10, so it is implied
  4. DThe base only matters for small n
7.Hard

The halting problem shows that:

  1. ANo algorithm can decide for every program and input whether it halts
  2. BEvery program eventually halts
  3. CSome programs run faster on faster computers, so halting depends on hardware
  4. DLoops should be avoided
8.Hard

To show that a new problem X is NP-hard, what must you do?

  1. AShow that X can be verified in polynomial time
  2. BShow that X has no polynomial algorithm for small inputs
  3. CReduce a known NP-hard problem to X in polynomial time
  4. DReduce X to a known NP-hard problem in polynomial time

Answer key

  1. 1. D · Ω (Big Omega)
  2. 2. B · O(log n)
  3. 3. B · Big O
  4. 4. C · An array that is already sorted
  5. 5. C · Insertion sort has little overhead and is fast on small or nearly sorted inputs
  6. 6. A · Logarithms with different bases differ only by a constant factor
  7. 7. A · No algorithm can decide for every program and input whether it halts
  8. 8. C · Reduce a known NP-hard problem to X in polynomial time

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