Data Structures & AlgorithmsModerateProduct-company MCQ pattern
Using the master theorem, what is the solution of T(n) = 4T(n/2) + n²?
- A. Θ(n³)
- B. Θ(n² log n)
- C. Θ(n log n)
- D. Θ(n²)
Correct answer: B. Θ(n² log n)
n^(log₂ 4) = n² equals f(n), which is case 2, so an extra log factor appears: Θ(n² log n). Answering Θ(n²) misses the log that comes from the equal work at every level.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- What is the solution of T(n) = T(n/3) + T(2n/3) + n?
- What is the length of the longest common subsequence of ALGORITHM and LOGARITHM?
- What is the edit distance (insert, delete, replace, each cost 1) between FLASK and FLOSSY?
- In how many ways can 10 be made from coins of 2, 3 and 5 (unlimited supply, order does not matter)?
- 0/1 knapsack, capacity 7. Items (weight, value): (1, 1), (3, 4), (4, 5), (5, 7). What is the maximum total value?
- Matrices A (10 × 20), B (20 × 30) and C (30 × 40) are to be multiplied. What is the minimum number of scalar multiplications?