GATE / CS ARCHIVE

GATE CSE 1997 / QUESTION 15(b)

Solve the bivariate recurrence

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

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

Recurrences & Generating Functions

Question 15(b), 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,m).
Question 15(b), 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,m).
Tap to enlarge
Answer & solution

Answer: C(n+m,n) = C(n+m,m). (no official key was published)

The boundary values are F(0,m)=F(n,0)=1. Compare them with G(n,m)=C(n+m,n): G(0,m)=C(m,0)=1 and G(n,0)=C(n,n)=1, so the axes agree.

For n,m≥1, Pascal's identity gives

G(n−1,m)+G(n,m−1)
=C(n+m−1,n−1)+C(n+m−1,n)
=C(n+m,n)=G(n,m).

Thus G obeys exactly the same recurrence and boundaries as F. Induction on n+m proves equality: each interior value depends only on two smaller sums, so once their equality is established the new value also agrees. Therefore F(n,m)=C(n+m,n)=C(n+m,m).

A useful combinatorial interpretation is the number of lattice paths from (0,0) to (n,m) using n horizontal and m vertical moves. Select which n of the n+m positions are horizontal. On either axis there is only one path, and every interior path arrives from one of its two preceding grid points, explaining both the boundary and recurrence.

The answer is symmetric in n and m, as the function definition requires. At m=2 it specializes to (n+1)(n+2)/2. This formula is the returned value, not the number of function activations; the directly recursive implementation recomputes many identical arguments, which the next subpart counts separately.

Original paper, page 8