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 memoisation?
AStoring the results of function calls so repeated calls are answered from memory
BFreeing memory after a function returns
CWriting comments next to each line of code
DConverting recursion into an equivalent loop automatically so no call stack is needed
2.Easy
An O(n²) algorithm takes 1 second for n = 1000. About how long does it take for n = 2000?
A4 seconds
B1 second
C8 seconds
D2 seconds
3.Easy
What is the Big O of 3n² + 5n + 2?
AO(n²)
BO(5n)
CO(3n²)
DO(n³)
4.Medium
Why is the base of a logarithm usually left out in Big O, as in O(log n)?
AAll logarithms in computer science have base 10, so it is implied
BLogarithms are always rounded to integers
CLogarithms with different bases differ only by a constant factor
DThe base only matters for small n
5.Medium
Is it correct to say that an O(n²) algorithm is also O(n³)?
ANo, because n³ is smaller than n² for large n
BNo, because Big O must always state the exact growth rate of the function
CYes, but only if n is smaller than 100
DYes, because Big O is an upper bound and n² grows no faster than n³
6.Medium
What does the Floyd–Warshall algorithm compute, and how fast?
AShortest paths from one source vertex to all others in O(V + E)
BA minimum spanning tree in O(E log V)
CA topological order in O(V²)
DShortest paths between all pairs of vertices in O(V³)
7.Hard
Why can Dijkstra's algorithm give wrong results when some edge weights are negative?
ANegative numbers cannot be stored in a priority queue
BIt goes into an infinite loop on every negative edge
CA vertex is finalised when extracted, but a later negative edge could still give it a shorter path
DIt only works on undirected graphs
8.Hard
A problem is NP-complete if it is:
AIn NP and every NP problem reduces to it in polynomial time
BImpossible to solve
COutside NP but harder than all NP problems, such as the halting problem
DSolvable in polynomial time
Answer key
1. A · Storing the results of function calls so repeated calls are answered from memory
2. A · 4 seconds
3. A · O(n²)
4. C · Logarithms with different bases differ only by a constant factor
5. D · Yes, because Big O is an upper bound and n² grows no faster than n³
6. D · Shortest paths between all pairs of vertices in O(V³)
7. C · A vertex is finalised when extracted, but a later negative edge could still give it a shorter path
8. A · In NP and every NP problem reduces to it in polynomial time
Full step-by-step solutions: practise this topic on examproblems.com.