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 O(2ⁿ) growth called?
- APolynomial
- BLinear
- CLogarithmic
- DExponential
2.Easy
An algorithm with two nested loops, each running n times, typically has which complexity?
- AO(n²)
- BO(log n)
- CO(n)
- DO(2n)
3.Easy
What is the time complexity of finding the largest value in an unsorted array of n numbers?
- AO(1)
- BO(n)
- CO(log n)
- DO(n log n)
4.Medium
The time complexity of naive recursive Fibonacci (fib(n) = fib(n−1) + fib(n−2)) is:
- AExponential
- BLinear
- CLogarithmic
- DConstant
5.Medium
What is the time complexity of multiplying two n × n matrices with the standard triple loop?
- AO(n²)
- BO(n² log n)
- CO(n³)
- DO(n)
6.Medium
How much stack space does a simple recursive factorial function fact(n) = n × fact(n − 1) use?
- AO(n²)
- BO(log n)
- CO(1)
- DO(n)
7.Hard
How do n! and 2ⁿ compare for large n?
- A2ⁿ grows faster than n!
- BThey grow at the same rate
- Cn! is O(n²)
- Dn! grows faster than 2ⁿ
8.Hard
A problem is NP-complete if it is:
- ASolvable in polynomial time
- BIn NP and every NP problem reduces to it in polynomial time
- COutside NP but harder than all NP problems, such as the halting problem
- DImpossible to solve