1.Easy
What does binary search require of its input?
- AThe array length must be a power of two
- BThe array must be sorted
- CThe array must have no more than 1000 elements
- DThe array must contain only positive numbers
2.Easy
What is the base case of a recursive function?
- AThe first line of the function
- BA case that is answered directly without making another recursive call
- CThe case with the largest input, which is handled before any recursive calls
- DThe call that uses the most memory
3.Easy
Which of these running times is polynomial?
- AO(n³)
- BO(2ⁿ)
- CO(nⁿ)
- DO(n!)
4.Medium
Dynamic programming is useful when a problem has:
- AOnly random inputs
- BOverlapping subproblems and optimal substructure
- CNo subproblems at all, so it can be solved in one step
- DA single loop
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
What is the time complexity of the standard dynamic programming algorithm for the longest common subsequence of strings of lengths m and n?
- AO(mn)
- BO(mn log n)
- CO(m + n)
- DO(2m+n)
7.Hard
Why is the average lookup in a hash table O(1) but the worst case O(n)?
- AKeys must be sorted first
- BHash functions are slow
- CMany keys may collide into the same bucket
- DArrays have O(n) access
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. B · The array must be sorted
- 2. B · A case that is answered directly without making another recursive call
- 3. A · O(n³)
- 4. B · Overlapping subproblems and optimal substructure
- 5. D · O(n³)
- 6. A · O(mn)
- 7. C · Many keys may collide into the same bucket
- 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.