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 log₂ 1024?

  1. A10
  2. B512
  3. C12
  4. D32
2.Easy

What is the time complexity of finding the largest value in an unsorted array of n numbers?

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

What are the three steps of a divide-and-conquer algorithm?

  1. AGuess, check, repeat
  2. BRead, compute, write
  3. CSort, search, return
  4. DDivide, conquer, combine
4.Medium

In a sorted array, you look for two elements that sum to a target by moving one pointer from each end inwards. What is the time complexity?

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

What is the running time of LSD radix sort on n integers with d digits in base k?

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

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

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

The halting problem shows that:

  1. ALoops should be avoided
  2. BNo algorithm can decide for every program and input whether it halts
  3. CSome programs run faster on faster computers, so halting depends on hardware
  4. DEvery program eventually halts
8.Hard

Why does any comparison-based search in a sorted array need Ω(log n) comparisons in the worst case?

  1. AComparisons take logarithmic time each
  2. BBinary search is the only possible algorithm, and it needs log₂ n comparisons
  3. CEvery element must be compared at least once
  4. DA decision tree with n possible outcomes must have depth at least log₂ n

Answer key

  1. 1. A · 10
  2. 2. D · O(n)
  3. 3. D · Divide, conquer, combine
  4. 4. C · O(n)
  5. 5. C · O(d(n + k))
  6. 6. B · O(log n)
  7. 7. B · No algorithm can decide for every program and input whether it halts
  8. 8. D · A decision tree with n possible outcomes must have depth at least log₂ n

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