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 grows slowest as n becomes large?

  1. AO(n log n)
  2. BO(log n)
  3. CO(n)
  4. DO(n²)
2.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 strictly faster than g
  3. Cf grows strictly slower than g
  4. Df grows at the same rate as g, bounded above and below by constant multiples of g
3.Easy

Which complexity class grows fastest for large n?

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

Breadth-first search on an unweighted graph finds:

  1. AThe minimum spanning tree
  2. BA topological order in all graphs
  3. CShortest paths in graphs that contain negative edge weights
  4. DShortest paths in number of edges from the start node
5.Medium

The lower bound for comparison-based sorting in the worst case is:

  1. AΩ(log n)
  2. BΩ(n log n)
  3. CΩ(n)
  4. DΩ(n²)
6.Medium

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

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

The halting problem shows that:

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

Shortest simple paths can be found in polynomial time. What is known about finding the longest simple path between two vertices in a general graph?

  1. AIt can be solved by Dijkstra's algorithm with negated weights
  2. BIt is undecidable
  3. CIt is always solvable in O(V + E)
  4. DIt is NP-hard

Answer key

  1. 1. B · O(log n)
  2. 2. D · f grows at the same rate as g, bounded above and below by constant multiples of g
  3. 3. C · O(2ⁿ)
  4. 4. D · Shortest paths in number of edges from the start node
  5. 5. B · Ω(n log n)
  6. 6. D · O(log n)
  7. 7. C · No algorithm can decide for every program and input whether it halts
  8. 8. D · It is NP-hard

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