GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Let T(n) = T(n − ⌊√n⌋) + 1 for n > 1 and T(1) = 0. Which is the tight bound?
- A. Θ(log n)
- B. Θ(n)
- C. Θ(√n)
- D. Θ(√n log n)
Correct answer: C. Θ(√n)
While n shrinks from N to N/2, each step removes at least √(N/2), so that phase takes O(√N) steps, and the phases N, N/2, N/4, … cost a geometric series: Θ(√N) overall (numerically T(n)/√n → 2). It is not Θ(log n) because the steps subtract, rather than divide.
More Algorithms questions
- Let T(n) = T(n/2) + n(2 − cos n) (n in radians) with T(1) = 1. Which statement about T(n) is correct?
- 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)?