GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 4(a)

Evaluate a binomial recurrence

Algorithms · Asymptotic Analysis & Recurrences · Full GATE CSE 1995 paper

GATE 1995, Q4(a) Descriptive
Report issue

Asymptotic Analysis & Recurrences

Question 4(a), GATE 1995: GET(A,B)=1 if B=0; otherwise GET(A,B)=0 if A<B; otherwise GET(A−1,B)+GET(A−1,B−1). Find GET(3,2).
Tap to enlarge
Answer & solution

Answer: 3 (no official key was published)

Step through it (23 steps)

The base case with B=0 represents the single way to choose no elements. The A<B case represents the impossibility of choosing more elements than are available. The recursive case separates choices according to whether the last element is excluded or included; it is Pascal’s binomial recurrence.

Expand the requested call rather than assuming a closed form: GET(3,2)=GET(2,2)+GET(2,1). The first term is GET(1,2)+GET(1,1)=0+[GET(0,1)+GET(0,0)]=0+0+1=1. The second is GET(1,1)+GET(1,0)=1+1=2. Hence the result is 3, agreeing with the binomial coefficient C(3,2). The ordering of the tests matters at (0,0): B=0 is tested first and returns 1.

Original paper, page 6