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 does the worst-case running time of an algorithm describe?

  1. AThe time it takes on the smallest input
  2. BThe expected time it takes on a random input of size n
  3. CThe maximum time it takes over all inputs of size n
  4. DThe time it takes on a slow computer
2.Easy

Which complexity class grows fastest for large n?

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

What is recursion?

  1. AA type of data structure
  2. BA function that calls itself on smaller inputs
  3. CA sorting method
  4. DA loop that never ends
4.Medium

What is the worst-case time complexity of quicksort?

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

The time complexity of naive recursive Fibonacci (fib(n) = fib(n−1) + fib(n−2)) is:

  1. ALogarithmic
  2. BExponential
  3. CConstant
  4. DLinear
6.Medium

What is the amortised time complexity of appending to a dynamic array that doubles its capacity when full?

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

What is the running time of Dijkstra's algorithm with a binary heap on a graph with V vertices and E edges?

  1. AO(V + E)
  2. BO(V³)
  3. CO(V × E)
  4. DO((V + E) log V)
8.Hard

Which algorithm finds a minimum spanning tree by repeatedly adding the cheapest edge that does not form a cycle?

  1. APrim's algorithm starting from one node
  2. BDijkstra's algorithm
  3. CKruskal's algorithm
  4. DFloyd–Warshall

Answer key

  1. 1. C · The maximum time it takes over all inputs of size n
  2. 2. A · O(2ⁿ)
  3. 3. B · A function that calls itself on smaller inputs
  4. 4. A · O(n²)
  5. 5. B · Exponential
  6. 6. B · O(1)
  7. 7. D · O((V + E) log V)
  8. 8. C · Kruskal's algorithm

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