ProgrammingModerateTCS NQT · Infosys

T(0) = 0 and T(n) = T(n-1) + n for n >= 1. What is T(10)?

  1. A. 45
  2. B. 55
  3. C. 50
  4. D. 65

Correct answer: B. 55

T(n) is the sum 1 + 2 + ... + n, which for n = 10 is 55. Replacing the recursion with the closed form n(n+1)/2 is safe here because the values are small.

More C Programming questions

Exams that ask this topic