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 complexity class grows fastest for large n?

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

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

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

What is the running time of counting sort for n integers in the range 0 to k?

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

With coins of 1, 3 and 4 and an amount of 6, how many coins does the greedy "largest coin first" method use, compared to the optimum?

  1. AGreedy uses 4 coins; the optimum is 3
  2. BGreedy uses 2 coins; the optimum is 2
  3. CGreedy uses 3 coins; the optimum is 3
  4. DGreedy uses 3 coins; the optimum is 2
5.Medium

Which algorithm finds the shortest paths from one source in a graph with non-negative edge weights?

  1. ADepth-first search
  2. BKruskal's algorithm
  3. CDijkstra's algorithm
  4. DBellman–Ford is required in all cases
6.Medium

Why does dynamic programming give no real speed-up for merge sort?

  1. ADynamic programming only works on graph problems, not on arrays
  2. BMerge sort has no recursive structure
  3. CIts subproblems do not overlap, so there is nothing to reuse
  4. DMerge sort is already O(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³)
  2. BO(V + E)
  3. CO((V + E) log V)
  4. DO(V × E)
8.Hard

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

  1. AKruskal's algorithm
  2. BPrim's algorithm starting from one node
  3. CFloyd–Warshall
  4. DDijkstra's algorithm

Answer key

  1. 1. A · O(2ⁿ)
  2. 2. D · O(n²)
  3. 3. B · O(n + k)
  4. 4. D · Greedy uses 3 coins; the optimum is 2
  5. 5. C · Dijkstra's algorithm
  6. 6. C · Its subproblems do not overlap, so there is nothing to reuse
  7. 7. C · O((V + E) log V)
  8. 8. A · Kruskal's algorithm

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