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 time complexity of linear search in an unsorted array of n elements (worst case)?
AO(log n)
BO(n²)
CO(1)
DO(n)
2.Easy
What does binary search require of its input?
AThe array must contain only positive numbers
BThe array length must be a power of two
CThe array must have no more than 1000 elements
DThe array must be sorted
3.Easy
Which of these grows slowest as n becomes large?
AO(n log n)
BO(log n)
CO(n²)
DO(n)
4.Medium
What does the recurrence T(n) = T(n − 1) + O(n) solve to?
AO(n log n)
BO(n²)
CO(2ⁿ)
DO(n)
5.Medium
Which algorithm finds the shortest paths from one source in a graph with non-negative edge weights?
ABellman–Ford is required in all cases
BKruskal's algorithm
CDepth-first search
DDijkstra's algorithm
6.Medium
Breadth-first search on an unweighted graph finds:
AThe minimum spanning tree
BA topological order in all graphs
CShortest paths in graphs that contain negative edge weights
DShortest paths in number of edges from the start node
7.Hard
Insertion sort runs in O(n) on sorted input. Does this contradict the Ω(n log n) lower bound for comparison sorting?
AYes, but only for arrays shorter than 100
BNo, the lower bound applies to the worst case over all inputs, not to every input
CYes, the lower bound is therefore wrong
DNo, because insertion sort is not a comparison sort
8.Hard
Using the master theorem, T(n) = 8T(n/2) + O(n²) solves to:
AΘ(n³)
BΘ(n² log n)
CΘ(n²)
DΘ(n log n)
Answer key
1. D · O(n)
2. D · The array must be sorted
3. B · O(log n)
4. B · O(n²)
5. D · Dijkstra's algorithm
6. D · Shortest paths in number of edges from the start node
7. B · No, the lower bound applies to the worst case over all inputs, not to every input
8. A · Θ(n³)
Full step-by-step solutions: practise this topic on examproblems.com.