GATE Computer ScienceHardGATE CS (PYQ pattern)
Let T(n) = T(n/2) + n(2 − cos n) (n in radians) with T(1) = 1. Which statement about T(n) is correct?
- A. T(n) = Θ(n log n), because cos n oscillates
- B. T(n) = Θ(n), even though the regularity condition fails
- C. T(n) = Θ(1), because the cos term cancels
- D. The recurrence has no asymptotic bound
Correct answer: B. T(n) = Θ(n), even though the regularity condition fails
Since 1 ≤ 2 − cos n ≤ 3, the f term lies between n and 3n, so T(n) is between n and 6n by unrolling the geometric series: Θ(n). The regularity condition of the master theorem cannot be verified because f oscillates, but the direct bound still works.
More Algorithms questions
- How many times does x++ execute? for (i = 1; i <= 64; i = 2) for (j = 1; j <= i; j++) for (k = j; k <= i; k = 2) x++;
- How many times does x++ execute? for (i = 1; i <= 200; i++) { j = 1; while (j <= i) { x++; j = 3; } }
- How many balanced parenthesis strings with 6 pairs have nesting depth at most 2?
- In how many ways can a 2 × 10 rectangle be tiled with 2 × 1 dominoes (either orientation) and 2 × 2 squares?
- How many permutations of 7 distinct items have every cycle of length at least 3 (no fixed points and no 2-cycles)?
- Twelve symbols, all with the same frequency 1, are encoded with an optimal Huffman code. What is the total number of bits to encode one…