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 a brute-force algorithm?

  1. AOne that always uses recursion
  2. BOne that guesses an answer at random
  3. COne that tries all possible candidate solutions
  4. DOne that runs on many processors
2.Easy

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

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

What is O(2ⁿ) growth called?

  1. ALogarithmic
  2. BPolynomial
  3. CExponential
  4. DLinear
4.Medium

A greedy algorithm:

  1. AAlways gives the optimal solution
  2. BUses only recursion
  3. CMakes the locally best choice at each step
  4. DTries every possible solution
5.Medium

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

  1. ABellman–Ford is required in all cases
  2. BDijkstra's algorithm
  3. CDepth-first search
  4. DKruskal's algorithm
6.Medium

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

  1. ANo, because n³ is smaller than n² for large n
  2. BYes, but only if n is smaller than 100
  3. CYes, because Big O is an upper bound and n² grows no faster than n³
  4. DNo, because Big O must always state the exact growth rate of the function
7.Hard

Which bound is correct for log(n!)?

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

Which definition of the class P is correct?

  1. AProblems whose solutions can be checked but never found in polynomial time
  2. BDecision problems solvable by a deterministic algorithm in polynomial time
  3. CProblems that need exponential time on every computer
  4. DProblems that can be solved in parallel

Answer key

  1. 1. C · One that tries all possible candidate solutions
  2. 2. D · O(n + k)
  3. 3. C · Exponential
  4. 4. C · Makes the locally best choice at each step
  5. 5. B · Dijkstra's algorithm
  6. 6. C · Yes, because Big O is an upper bound and n² grows no faster than n³
  7. 7. C · Θ(n log n)
  8. 8. B · Decision problems solvable by a deterministic algorithm in polynomial time

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