GATE / CS ARCHIVE

GATE CSE 1997 / QUESTION 15(a)

Evaluate the two-column recurrence

Discrete Mathematics · Recurrences & Generating Functions · Full GATE CSE 1997 paper

GATE 1997, Q15(a) 2 marks · Descriptive
Report issue

Recurrences & Generating Functions

Question 15(a), GATE 1997: For positive integers n,m, consider the directly recursive, nonmemoized function
function F(n,m:integer):integer;
begin
  if (n<=0) or (m<=0) then F:=1
  else F:=F(n-1,m)+F(n,m-1)
end.
Use C(s,t)=C(s−1,t)+C(s−1,t−1).
Find F(n,2).
Question 15(a), GATE 1997: For positive integers n,m, consider the directly recursive, nonmemoized function
function F(n,m:integer):integer;
begin
  if (n<=0) or (m<=0) then F:=1
  else F:=F(n-1,m)+F(n,m-1)
end.
Use C(s,t)=C(s−1,t)+C(s−1,t−1).
Find F(n,2).
Tap to enlarge
Answer & solution

Answer: (n+1)(n+2)/2 = C(n+2,2). (no official key was published)

Start with m=1. The recurrence says F(n,1)=F(n−1,1)+F(n,0)=F(n−1,1)+1, and F(0,1)=1. Therefore F(n,1)=n+1.

Now use m=2. We get F(n,2)=F(n−1,2)+F(n,1)=F(n−1,2)+(n+1), with F(0,2)=1. Summing the increments from 1 through n gives

F(n,2)=1+Σ_(r=1)n(r+1)
=1+n(n+1)/2+n
=(n+1)(n+2)/2.

This equals C(n+2,2), anticipating the general binomial formula. A direct induction check also works: the proposed formula for n−1 is n(n+1)/2; adding n+1 gives (n+1)(n+2)/2. The base n=0 gives 1 as required.

For n=1, F(1,2)=F(0,2)+F(1,1)=1+2=3, consistent with the formula. The offset matters: n(n+1)/2 would correspond to a different boundary condition and would incorrectly give 1 when n=1. Both axes in this program have value 1, not 0.

Original paper, page 8