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

Accessing an element by index in an array takes:

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

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

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

What is O(2ⁿ) growth called?

  1. APolynomial
  2. BExponential
  3. CLogarithmic
  4. DLinear
4.Medium

Which sorting algorithm is stable?

  1. AQuicksort (typical in-place version)
  2. BHeap sort
  3. CMerge sort
  4. DSelection sort (typical version)
5.Medium

What is the time complexity of multiplying two n × n matrices with the standard triple loop?

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

A function runs one loop of n iterations and then, separately, another loop of n iterations. What is its time complexity?

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

What did the Cook–Levin theorem establish?

  1. AThe Boolean satisfiability problem (SAT) is NP-complete
  2. BP is not equal to NP
  3. CEvery NP problem can be solved in exponential time
  4. DThe halting problem is undecidable
8.Hard

What is the difference between an undecidable problem and an intractable one?

  1. AUndecidable problems are in NP, while intractable problems are in P
  2. BBoth mean the problem has no algorithm at all
  3. CAn undecidable problem has no algorithm for all inputs; an intractable one has one, but it is too slow
  4. DIntractable problems cannot be solved by any algorithm, while undecidable ones only need exponential time

Answer key

  1. 1. B · O(1)
  2. 2. A · O(n + k)
  3. 3. B · Exponential
  4. 4. C · Merge sort
  5. 5. B · O(n³)
  6. 6. C · O(n)
  7. 7. A · The Boolean satisfiability problem (SAT) is NP-complete
  8. 8. C · An undecidable problem has no algorithm for all inputs; an intractable one has one, but it is too slow

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