ProgrammingHardGATE CS · Campus placements
C(0) = 1 and C(n) = sum over i from 0 to n-1 of C(i) * C(n-1-i). What is C(4)?
- A. 12
- B. 16
- C. 14
- D. 42
Correct answer: C. 14
C(1) = 1, C(2) = 2, C(3) = 5 and C(4) = 1*5 + 1*2 + 2*1 + 5*1 = 14. This is the Catalan recurrence, which counts balanced bracket strings.
More C Programming questions
- A 3 x 3 grid holds 1 to 9 row by row, so row 0 is 1 2 3, row 1 is 4 5 6 and row 2 is 7 8 9. What is the sum of the 2 x 2 block with rows 1…
- In the sorted array {1, 2, 4, 6, 8, 9}, how many unordered pairs of distinct elements sum to 17?
- What is the largest sum of any three consecutive elements of {2, 1, 5, 1, 3, 2}?
- The sorted array is {1, 3, 6, 6, 8}. What is the index of the first occurrence of 6?
- How many integers in the range 0 to 15 have an even number of 1 bits in binary?
- How many 1 bits are set in 2^20 - 1 (a 32-bit unsigned value)?