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 the best-case time complexity of insertion sort, on an already sorted array?

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

Which of these grows slowest as n becomes large?

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

An algorithm's running time is O(n). What is this growth called?

  1. AQuadratic
  2. BLogarithmic
  3. CLinear
  4. DConstant
4.Medium

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

  1. AInsertion sort is O(n log n) in the worst case
  2. BRecursive algorithms cannot handle arrays below 10 elements
  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

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

Which sorting algorithm is stable?

  1. ASelection sort (typical version)
  2. BMerge sort
  3. CHeap sort
  4. DQuicksort (typical in-place version)
7.Hard

Why does binary search not give O(log n) time on a singly linked list?

  1. ABinary search needs at least twice the memory
  2. BReaching the middle element takes O(n) steps, since there is no direct index access
  3. CComparisons on linked list nodes are slower
  4. DLinked lists cannot be sorted
8.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

Answer key

  1. 1. B · O(n)
  2. 2. B · O(log n)
  3. 3. C · Linear
  4. 4. C · Insertion sort has little overhead and is fast on small or nearly sorted inputs
  5. 5. A · O(n³)
  6. 6. B · Merge sort
  7. 7. B · Reaching the middle element takes O(n) steps, since there is no direct index access
  8. 8. B · No algorithm can decide for every program and input whether it halts

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