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 are the three steps of a divide-and-conquer algorithm?

  1. ASort, search, return
  2. BDivide, conquer, combine
  3. CRead, compute, write
  4. DGuess, check, repeat
2.Easy

A loop starts with i = 1 and doubles i each iteration until i > n. How many iterations does it run?

  1. AAbout n²
  2. BAbout log₂ n
  3. CAbout n / 2
  4. DAbout n
3.Easy

Which notation describes a lower bound on growth?

  1. Ao (little o)
  2. BΘ (Big Theta)
  3. CΩ (Big Omega)
  4. DO (Big O)
4.Medium

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

  1. AMerge sort is already O(n)
  2. BDynamic programming only works on graph problems, not on arrays
  3. CIts subproblems do not overlap, so there is nothing to reuse
  4. DMerge sort has no recursive structure
5.Medium

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

  1. AKruskal's algorithm
  2. BDepth-first search
  3. CBellman–Ford is required in all cases
  4. DDijkstra's algorithm
6.Medium

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

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

What would follow if someone found a polynomial-time algorithm for one NP-complete problem?

  1. AThe halting problem would become decidable
  2. BOnly that one problem would move into P
  3. CEvery problem in NP could be solved in polynomial time, so P = NP
  4. DAll exponential-time algorithms would immediately run in linear time
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 is undecidable
  2. BIt can be solved by Dijkstra's algorithm with negated weights
  3. CIt is always solvable in O(V + E)
  4. DIt is NP-hard

Answer key

  1. 1. B · Divide, conquer, combine
  2. 2. B · About log₂ n
  3. 3. C · Ω (Big Omega)
  4. 4. C · Its subproblems do not overlap, so there is nothing to reuse
  5. 5. D · Dijkstra's algorithm
  6. 6. C · It grows one tree from a start vertex, adding the cheapest edge that leaves the tree
  7. 7. C · Every problem in NP could be solved in polynomial time, so P = NP
  8. 8. D · It is NP-hard

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