GATE / CS ARCHIVE

SUBJECT COLLECTION

Discrete Mathematics · Recurrences & Generating Functions

15 questions, newest first

GATE CSE has asked 15 questions on Recurrences & Generating Functions (Discrete Mathematics) from 1997 to 2023, in 11 of the 46 papers; the most recent is in GATE CSE 2023. In the last five years it carried 0.6 marks per 100-mark paper on average, against 0.6 since 2003. Since 2014 the questions have been 5 MCQ, 4 NAT and 1 MSQ. 2 groups of questions here are solved the same way; “One per method” keeps the newest of each.

Browse topics
1 mark · MCQ
Report issue

Recurrences & Generating Functions

Question 15, GATE 2023: The Lucas sequence has L1=1,L2=3 and Ln=L(n−1)+L(n−2). Put α=(1+√5)/2, β=(1−√5)/2, γ=(1−√5)/3. Which is Ln? A αⁿ+βⁿ; B αⁿ−γⁿ; C αⁿ+γⁿ; D αⁿ−βⁿ.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

The characteristic roots of r²=r+1 are α=(1+√5)/2 and β=(1−√5)/2. The sequence αⁿ+βⁿ satisfies the recurrence; at n=1 it is 1, and at n=2 it is(α+β)²−2αβ=1+2=3. These initial values uniquely specify the sequence, so A.

Teaching detail. For a recurrence Ln=L(n−1)+L(n−2), trying a solution rⁿ gives r²−r−1=0. Each root therefore yields a valid exponential sequence, and linear combinations remain solutions. Here α+β=1 and αβ=−1 establish the initial values without numerical square-root calculations. Uniqueness follows inductively: if two sequences agree at positions 1 and 2, their recurrence makes them agree at 3 and then at every later position. Checking only one initial value would not establish the result.

Original paper, page 12 · Answer key

2 marks · MCQ
Report issue

Recurrences & Generating Functions

Question 36, GATE 2022: For n≥0, a_n=n+1 if n is odd, and 1 otherwise. Find the ordinary generating function. Options all include +1/(1−x): A x(1+x²)/(1−x²)²; B x(3−x²)/(1−x²)²; C 2x/(1−x²)²; D x/(1−x²)².
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Write an=1+n for odd n and 1 for even n. The baseline generating function is 1/(1−x). Also Σ_(odd n≥1) n xn=x d/dx[x/(1−x²)]=x(1+x²)/(1−x²)². Adding gives 1/(1−x)+x(1+x²)/(1−x²)², option A.

The first coefficients are 1,2,1,4,1,6,… . Begin with the all-ones series, then add x+3x³+5x⁵+… . Differentiating x+x³+x⁵+…=x/(1−x²) and multiplying by x produces exactly that odd-index correction. This also checks that the constant coefficient remains 1.

Original paper, page 24 · Answer key

2 marks · MSQ
Report issue

Recurrences & Generating Functions

Question 52, GATE 2022: For the adjacency matrix A of an n-vertex simple undirected unweighted graph, select true statements: A diagonal of A² equals degrees; B connectivity implies A^(n−1)+I has no zero entry; C sum of A's entries ≤2(n−1) implies acyclic; D a 1 in every row/column implies connectivity.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A

The ith diagonal of A squared is sum_j A_ij A_ji=sum_j A_ij, since the matrix is symmetric with binary entries. It therefore equals degree(i), proving A. B fails for the three-vertex path: no length-two walk connects adjacent vertices, so that off-diagonal entry of A2+I is zero. C fails for a triangle plus an isolated vertex: n=4 and the entry sum is 6=2(n-1), yet there is a cycle. D fails for two disjoint edges, which give no zero row or column but are disconnected.

The distinction in B is walks of exactly n−1 edges versus paths of at most n−1 edges. Connectivity guarantees the latter, not the former. Adding I supplies only length-zero diagonal walks; it does not add all smaller powers needed to test reachability. In D, absence of isolated vertices still permits several nontrivial components.

Original paper, page 34 · Answer key

1 mark · MCQ
Report issue

Generating function of an arithmetic sequence

Recurrences & Generating Functions

Question 1, GATE 2018: For a_n=2n+3, n≥0, find the ordinary generating function Σa_n x^n. Choices: A 3/(1−x)²; B 3x/(1−x)²; C (2−x)/(1−x)²; D (3−x)/(1−x)².
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Method

Start from Σxn=1/(1−x). Differentiate to obtain Σn xn−1=1/(1−x)² and multiply by x. Linearity now separates the 2n part from the constant 3 part. Combining over one denominator gives numerator 2x+3(1−x)=3−x. A quick constant-term check requires value a0=3 at x=0, already ruling out B and C.

Solution

The ordinary generating function is sum(2n+3)xn=2x/(1−x)²+3/(1−x)=(3−x)/(1−x)², D, as a formal power series or for |x|<1.

Original paper, page 4 · Answer key

2 marks · NAT
Report issue

Recurrences & Generating Functions

Question 47, GATE 2017: The ordinary generating function of sequence (a_n) for n≥0 is (1+z)/(1−z)³. Find a3−a0.
Tap to enlarge
Answer & solution

Official answer: 15.0

Our answer: 15

1. Use the binomial-series identity (1-z)-3=Σ(n≥0)C(n+2,2)zn. Its first coefficients are 1,3,6,10,… .

2. Multiplication by 1+z adds each coefficient to the preceding one. Thus a0=1 and a3=C(5,2)+C(4,2)=10+6=16. Directly, (1+z)(1+3z+6z²+10z³+…)=1+4z+9z²+16z³+… .

3. Therefore a3-a0=16-1=15. More generally an=C(n+2,2)+C(n+1,2)=(n+1)² for n≥1. The numerator shifts coefficients; it cannot simply be ignored when reading a3.

Original paper, page 19 · Answer key

1 mark · MCQ
Report issue

Recurrences & Generating Functions

Question 2, GATE 2016: Let a_n count length-n binary strings with no consecutive 1s. Which recurrence holds? A: a_n=a_(n−1)+2a_(n−2). B: a_n=a_(n−1)+a_(n−2). C: a_n=2a_(n−1)+a_(n−2). D: a_n=2a_(n−1)+2a_(n−2).
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Partition valid n-bit strings by their last symbol. Those ending 0 append 0 to any valid (n−1)-bit string. Those ending 1 must end 01 and append 01 to a valid (n−2)-bit string. Hence an=an−1+an−2, B, with a0=1, a1=2.

The two cases must be disjoint and exhaustive. For n≥2, a valid string ends either in 0, or in 01; the latter is forced because a final 1 cannot follow another 1. Removing those suffixes gives arbitrary valid shorter strings and is reversible, so there is neither overcounting nor omission. For example a2=3 corresponds to 00,01,10, matching a1+a0=2+1. Initial values accompany the recurrence even though only the recurrence is requested.

Original paper, page 4 · Answer key

2 marks · NAT
Report issue

Recurrences & Generating Functions

Question 26, GATE 2016: Find the coefficient of x^12 in (x^3+x^4+x^5+x^6+...)^3.
Tap to enlarge
Answer & solution

Official answer: 10.0 : 10.0

Our answer: 10

Factor the series as x³/(1−x). Its cube is x⁹(1−x)−3, so the coefficient of x¹² equals that of x³ in(1−x)−3, namely C(5, 2)=10. Equivalently distribute three excess units across three exponents, each originally at least 3.

Each of the three factors contributes one exponent at least 3. Write those exponents as 3+i,3+j,3+k with i,j,k≥0. To total 12, their excesses must satisfy i+j+k=3. Stars-and-bars counts C(3+3−1,3−1)=10 solutions. The three factors are distinguishable, so choices such as(3,4,5) and(4,3,5) contribute separately; counting unordered partitions would undercount the coefficient.

Original paper, page 12 · Answer key

2 marks · NAT
Report issue

Recurrences & Generating Functions

Question 27, GATE 2016: The sequence satisfies a_1=8 and a_n=6n^2+2n+a_(n−1). If a_99=K×10^4, find K.
Tap to enlarge
Answer & solution

Official answer: 197.9 : 198.1

Our answer: 198

The initial a 1=8 equals 6·1²+2·1, so a 99=sum(n=1..99)(6n²+2n). Using sum n²=N(N+1)(2N+1)/6 and sum n=N(N+1)/2 gives N(N+1)(2N+2)=2N(N+1)². At 99 this is 1,980,000=198·10⁴, hence K=198.

Unrolling adds the increments 6n2+2n for n=2 through 99 to the base 8. Because 8 is exactly the same expression at n=1, one uniform sum covers all terms. Simplifying before substituting avoids large arithmetic:6Σn2+2Σn=N(N+1)(2N+1)+N(N+1)=2N(N+1)2. A quick check at N=1 gives 8 and at N=2 gives 36, agreeing with the recurrence. Divide the final value by 10000, not multiply, to recover K.

Original paper, page 12 · Answer key

2 marks · MCQ
Report issue

Recurrences & Generating Functions

Question 45, GATE 2015: Let a_n count n-bit strings containing two consecutive 1s. Which recurrence gives a_n? A a_(n−2)+a_(n−1)+2^(n−2); B a_(n−2)+2a_(n−1)+2^(n−2); C 2a_(n−2)+a_(n−1)+2^(n−2); D 2a_(n−2)+2a_(n−1)+2^(n−2).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Partition strings into mutually exclusive initial patterns 0,10,11. A leading 0 leaves a suffix of length n−1 that must contain 11. A leading 10 leaves length n−2 with the same requirement. A leading 11 already satisfies it, so all 2n−2 suffixes qualify. This gives A for n≥2 with a0=a1=0; as a check, a2=1 and a3=3.

Solution: Partition valid n-bit strings by prefixes 0, 10, 11. The first class contributes a(n−1), the second a(n−2), and the third has arbitrary remaining n−2 bits, contributing 2n−2. Hence a(n)=a(n−1)+a(n−2)+2n−2, A.

Original paper, page 17 · Answer key

2 marks · NAT
Report issue

Recurrences & Generating Functions

Question 49, GATE 2014: An n-pennant is an ordered sequence of 1s and 2s whose sum is n. For example (1,1,2) is a 4-pennant, and (1,2) differs from (2,1). There is one 1-pennant and two 2-pennants. How many 10-pennants exist?
Tap to enlarge
Answer & solution

Official answer: 88.9 to 89.1

Our answer: 89

1. Method and setup. Partition all sequences by their first symbol. Removing a leading 1 leaves an (n−1)-pennant; removing a leading 2 leaves an (n−2)-pennant. These classes are disjoint and exhaustive, yielding a Fibonacci-type recurrence without double counting different orders.

2. Work through the result and its assumptions. Let a 0=1 count the empty sequence and a 1=1. Partition sequences by their first entry 1 or 2: an=a(n−1)+a(n−2). The values through n=10 are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89. Thus there are 89 ten-pennants, inside the published interval.

Original paper, page 20 · Answer key

2 marks · MCQ
Report issue

Counting strings with no consecutive zeros

Recurrences & Generating Functions

Question 78, GATE 2008: Let xₙ count binary strings of length n containing no consecutive zeros. Which recurrence does it satisfy?

(A) xₙ=2xₙ₋₁
(B) xₙ=x⌊ₙ/₂⌋+1
(C) xₙ=x⌊ₙ/₂⌋+n
(D) xₙ=xₙ₋₁+xₙ₋₂
Question 78, GATE 2008: Let xₙ count binary strings of length n containing no consecutive zeros. Which recurrence does it satisfy?

(A) xₙ=2xₙ₋₁
(B) xₙ=x⌊ₙ/₂⌋+1
(C) xₙ=x⌊ₙ/₂⌋+n
(D) xₙ=xₙ₋₁+xₙ₋₂
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. Divide valid strings of length n≥2 by their first bit. A leading 1 can be followed by any valid length-(n−1) string.
2. A leading 0 must be followed by 1, leaving any valid length-(n−2) suffix. These two groups cannot overlap and cover every valid string.
3. Add their counts: xₙ=xₙ₋₁+xₙ₋₂, D. Initial values are x₀=1 and x₁=2, which are essential for numerical evaluation.

Original paper, page 17

2 marks · MCQ
Report issue

Coefficients of a squared geometric series

Recurrences & Generating Functions

Question 50, GATE 2005: The ordinary generating function of g(i), i≥0, is 1/(1−x)². Find g(i). GateForum options: A i; B i+1; C 2i; D 2^i. GFG inserts a constant-1 line before these and labels the five entries A 1; B i; C i+1; D 2i; E 2^i. Explain the coefficient rather than relying on a universal letter.
Tap to enlarge
Your answer
Answer & solution

Answer: C: i+1 (no official key was published)

Differentiate ∑(j≥0)xj=1/(1−x) for |x|<1: 1/(1−x)²=∑(j≥1)j xj−1=∑(i≥0)(i+1)xi. Thus g(i)=i+1. Preserve the mathematical answer, not a purported universal letter.

The geometric-series identity is valid as a formal power series, so differentiate coefficient by coefficient. The derivative of xj is jxj−1, and relabeling i=j−1 gives coefficient i+1. Alternatively multiplying two copies of Σxj shows that xi can be formed in i+1 ways, from pairs(0, i),(1, i−1),…,(i, 0). Both arguments yield the same coefficient and avoid the inconsistent option lettering.

Original paper, page 6

Descriptive
Report issue

Solve an affine recurrence

Recurrences & Generating Functions

Question 6(a), GATE 1998: Solve x_n=2x_(n−1)−1 for n>1, with x_1=2.
Question 6(a), GATE 1998: Solve x_n=2x_(n−1)−1 for n>1, with x_1=2.
Tap to enlarge
Answer & solution

Answer: x_n=2^(n−1)+1. (no official key was published)

The constant fixed point of the recurrence is 1, because 1=2·1−1. Subtract it by setting yn=xn−1. Then yn=2x_(n−1)−2=2y_(n−1), while y1=1. Iterating the resulting geometric recurrence gives yn=2n−1, so xn=2n−1+1 for all n≥1.

To verify rather than merely guess the formula, its first value is 20+1=2. Assuming xn−1=2n−2+1, substitution gives 2[2n−2+1]−1=2n−1+1, completing induction. Initial values 2,3,5,9,17 agree. The exponent is n−1 rather than n because the specified initial index is 1. The subtraction trick is useful for affine recurrences generally: shift by a fixed point to expose the homogeneous geometric part.

Original paper, page 6

2 marks · Descriptive
Report issue

Evaluate the two-column recurrence

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

2 marks · Descriptive
Report issue

Solve the bivariate recurrence

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