Skip to content
Mad4Study

Engineering & Science

GATE Computer Science

  • GATE CS
  • 2023 pattern
  • Algorithms
  • Master theorem
  • Medium

What is the solution of the recurrence T(n)=2T(n/2)+nT(n) = 2T(n/2) + n with T(1)=1T(1) = 1?

Asymptotic Analysis

Pick an option to check your answer.

Apply the master theorem with a=2a = 2, b=2b = 2, f(n)=nf(n) = n.

  1. Compute nlog⁡ba=nlog⁡22=nn^{\log_b a} = n^{\log_2 2} = n
  2. f(n)=Θ ⁣(nlog⁡ba)f(n) = \Theta\!\left(n^{\log_b a}\right), which is case 2
  3. So T(n)=Θ(nlog⁡n)T(n) = \Theta(n \log n) — the same recurrence as merge sort.

Why not the others

  • Θ(n)\Theta(n) counts only the work at the top level; there are log⁡n\log n levels, each costing nn.
  • Θ(n2)\Theta(n^2) would need a=4a = 4 subproblems, as in T(n)=4T(n/2)+nT(n) = 4T(n/2) + n.
  • Θ(log⁡n)\Theta(\log n) is the binary-search recurrence T(n)=T(n/2)+1T(n) = T(n/2) + 1, with one subproblem and constant extra work.

Report an error

GATE CS · Algorithms · Asymptotic Analysis