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. ADivide, conquer, combine
  2. BSort, search, return
  3. CRead, compute, write
  4. DGuess, check, repeat
2.Easy

What is log₂ 1024?

  1. A10
  2. B32
  3. C12
  4. D512
3.Easy

Which of these grows slowest as n becomes large?

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

Why do many library sorting routines switch to insertion sort for very small subarrays?

  1. ARecursive algorithms cannot handle arrays below 10 elements
  2. BInsertion sort is O(n log n) in the worst case
  3. CInsertion sort has little overhead and is fast on small or nearly sorted inputs
  4. DInsertion sort uses less memory than any other sorting algorithm on large inputs
5.Medium

Which statement about a recursive function without a reachable base case is correct?

  1. AThe compiler always turns it into a loop that ends safely
  2. BIt keeps calling itself until the call stack overflows
  3. CIt runs in O(1) time
  4. DIt returns 0 automatically
6.Medium

What does the recurrence T(n) = 2T(n − 1) + O(1) solve to?

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

What does the recurrence T(n) = 2T(n/2) + n log n solve to?

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

What is the time complexity of: for i = 1 to n: for (j = i; j ≤ n; j = j + i) do O(1) work?

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

Answer key

  1. 1. A · Divide, conquer, combine
  2. 2. A · 10
  3. 3. B · O(log n)
  4. 4. C · Insertion sort has little overhead and is fast on small or nearly sorted inputs
  5. 5. B · It keeps calling itself until the call stack overflows
  6. 6. B · O(2ⁿ)
  7. 7. C · Θ(n log² n)
  8. 8. C · O(n log n)

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