Data Structures & AlgorithmsVery hardProduct company OA
Match each recurrence to its tight bound: (P) T(n) = 2T(n/2) + n log n (Q) T(n) = 2T(n/2) + n / log n (R) T(n) = T(n/2) + log n (S) T(n) = 4T(n/2) + n² log n Which option is entirely correct?
- A. P: Θ(n log n), Q: Θ(n), R: Θ(log n), S: Θ(n² log n)
- B. P: Θ(n log² n), Q: Θ(n log n), R: Θ(log n · log log n), S: Θ(n³)
- C. P: Θ(n log² n), Q: Θ(n log log n), R: Θ(log² n), S: Θ(n² log² n)
- D. The master theorem gives no answer for any of them, so all four are Θ(n log n)
Correct answer: C. P: Θ(n log² n), Q: Θ(n log log n), R: Θ(log² n), S: Θ(n² log² n)
All four have f(n) = n^(log_b a) · (log n)^k, the gap the basic theorem leaves open. The extended rule: k > −1 gives Θ(n^(log_b a) · log^(k+1) n); k = −1 gives Θ(n^(log_b a) · log log n). P (k = 1): n log² n. Q (k = −1): Σ n / log(n/2ⁱ) = n · Σ 1/j over the levels = n log log n. R: a = 1, b = 2, f = log n (k = 1) → log² n. S: n² · log² n. The first option applies case 2 as if the log factor did not exist.
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
- A road network has n ≤ 2·10⁵ junctions and m ≤ 2·10⁵ roads; each road is either free (0) or tolled (1). You need the minimum number of…
- Which loop nests perform Θ(n log n) executions of work()? c / A / for (i = 1; i <= n; i++) for (j = i; j <= n; j += i) work(); / B / for…
- A full binary tree (every node has 0 or 2 children) has 10 internal nodes. How many leaves does it have?
- An undirected graph with V vertices and E edges is stored as adjacency lists. How many entries do all the lists hold in total?
- Which traversal should be used to free every node of a binary tree, so that no node is freed before its children?
- Keys 40, 20, 60, 10, 30, 50, 70, 25 are inserted into an empty BST. Then 20 is deleted (a node with two children is replaced by its…