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

What is the worst-case time complexity of insertion sort?

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

What is O(2ⁿ) growth called?

  1. ALogarithmic
  2. BPolynomial
  3. CLinear
  4. DExponential
3.Easy

What is log₂ 1024?

  1. A512
  2. B10
  3. C12
  4. D32
4.Medium

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

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

How does Prim's algorithm build a minimum spanning tree?

  1. AIt sorts all edges by weight and adds each one unless it would form a cycle in the forest
  2. BIt runs breadth-first search and keeps the BFS tree
  3. CIt removes the most expensive edge until no cycles remain
  4. DIt grows one tree from a start vertex, adding the cheapest edge that leaves the tree
6.Medium

Is it correct to say that an O(n²) algorithm is also O(n³)?

  1. ANo, because Big O must always state the exact growth rate of the function
  2. BYes, because Big O is an upper bound and n² grows no faster than n³
  3. CYes, but only if n is smaller than 100
  4. DNo, because n³ is smaller than n² for large n
7.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 is always solvable in O(V + E)
  2. BIt is undecidable
  3. CIt can be solved by Dijkstra's algorithm with negated weights
  4. DIt is NP-hard
8.Hard

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

  1. AΘ(n log n)
  2. BΘ(n log² n)
  3. CΘ(n)
  4. DΘ(n²)

Answer key

  1. 1. C · O(n²)
  2. 2. D · Exponential
  3. 3. B · 10
  4. 4. C · O(2ⁿ)
  5. 5. D · It grows one tree from a start vertex, adding the cheapest edge that leaves the tree
  6. 6. B · Yes, because Big O is an upper bound and n² grows no faster than n³
  7. 7. D · It is NP-hard
  8. 8. B · Θ(n log² n)

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