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 binary search on a sorted array?
AO(n log n)
BO(n)
CO(log n)
DO(1)
2.Easy
What is an algorithm?
AAny computer program that has a graphical interface
BA finite sequence of well-defined steps that solves a problem
CA data structure that stores numbers
DA programming language designed for writing mathematical formulas
3.Easy
What is the running time of counting sort for n integers in the range 0 to k?
AO(n log n)
BO(n + k)
CO(k log n)
DO(n²)
4.Medium
A greedy algorithm:
AUses only recursion
BMakes the locally best choice at each step
CTries every possible solution
DAlways gives the optimal solution
5.Medium
A recurrence T(n) = 2T(n/2) + O(n) solves to:
AO(n²)
BO(n log n)
CO(log n)
DO(n)
6.Medium
In the activity selection problem, which greedy rule always gives a maximum number of non-overlapping activities?
APick the activity that starts earliest
BPick the shortest activity first
CPick the activity that finishes earliest, then repeat with the compatible ones
DPick the activity with the fewest overlaps first, then repeat with the compatible ones
7.Hard
What would follow if someone found a polynomial-time algorithm for one NP-complete problem?
AAll exponential-time algorithms would immediately run in linear time
BOnly that one problem would move into P
CThe halting problem would become decidable
DEvery problem in NP could be solved in polynomial time, so P = NP
8.Hard
The 0/1 knapsack problem solved with dynamic programming takes O(nW) time. Why is this called pseudo-polynomial?
ABecause the algorithm is randomised and its running time varies with each input
BBecause n is always small
CW is a number, so the time is exponential in the number of bits used to write W
DBecause it only works for W = 0
Answer key
1. C · O(log n)
2. B · A finite sequence of well-defined steps that solves a problem
3. B · O(n + k)
4. B · Makes the locally best choice at each step
5. B · O(n log n)
6. C · Pick the activity that finishes earliest, then repeat with the compatible ones
7. D · Every problem in NP could be solved in polynomial time, so P = NP
8. C · W is a number, so the time is exponential in the number of bits used to write W
Full step-by-step solutions: practise this topic on examproblems.com.