ProgrammingModerateTCS NQT · Infosys
T(0) = 0 and T(n) = T(n-1) + n for n >= 1. What is T(10)?
- A. 45
- B. 55
- C. 50
- 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
- What is gcd(48, 180) by Euclid's recursion?
- What is lcm(12, 18)?
- unsigned int u = 3; int s = -4; printf("%d", (int)u + s); What is printed?
- How many leading zero bits does the 16-bit unsigned value 0x0100 have?
- What is the popcount of (1ULL << 40) | (1ULL << 3)?
- c is a char holding '5'. What is printf("%d", (c - '0') 2)?