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 an upper bound on growth?

  1. ABig Theta
  2. BLittle omega
  3. CBig Omega
  4. DBig O
2.Easy

An algorithm's running time is O(n). What is this growth called?

  1. AConstant
  2. BQuadratic
  3. CLogarithmic
  4. DLinear
3.Easy

Which notation describes a lower bound on growth?

  1. AO (Big O)
  2. BΩ (Big Omega)
  3. Co (little o)
  4. DΘ (Big Theta)
4.Medium

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

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

What is the worst-case time complexity of quicksort?

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

Breadth-first search on an unweighted graph finds:

  1. AA topological order in all graphs
  2. BShortest paths in number of edges from the start node
  3. CShortest paths in graphs that contain negative edge weights
  4. DThe minimum spanning tree
7.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² log n)
  2. BΘ(n³)
  3. CΘ(n2)
  4. DΘ(nlog₂ 7), about n2.81
8.Hard

What did the Cook–Levin theorem establish?

  1. AThe halting problem is undecidable
  2. BP is not equal to NP
  3. CThe Boolean satisfiability problem (SAT) is NP-complete
  4. DEvery NP problem can be solved in exponential time

Answer key

  1. 1. D · Big O
  2. 2. D · Linear
  3. 3. B · Ω (Big Omega)
  4. 4. C · An array that is already sorted
  5. 5. D · O(n²)
  6. 6. B · Shortest paths in number of edges from the start node
  7. 7. D · Θ(nlog₂ 7), about n2.81
  8. 8. C · The Boolean satisfiability problem (SAT) is NP-complete

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