Question

A pennant is a sequence of numbers, each number being 1 or 2. An n-pennant is a sequence of numbers with sum equal to n. For example, (1,1,2) is a 4-pennant. The set of all possible 1-pennants is {(1)}, the set of all possible 2-pennants is {(2), (1,1)} and the set of all 3-pennants is {(2,1), (1,1,1), (1,2)}. Note that the pennant (1,2) is not the same as the pennant (2,1). The number of 10-pennants is ______________.

Official answer and solution
Accepted answers
88.9 to 89.1
From
Official GATE 2014 answer key

Solution

Set up a linear recurrence relation for the number of compositions of n into parts of size 1 and 2.

Let P(n)P(n) be the number of nn-pennants (ordered sequences of 1s and 2s that sum to nn).

Consider the last number in an nn-pennant:

  • If the last number is 1, the preceding sequence must sum to n−1n - 1, which is an (n−1)(n-1)-pennant. There are P(n−1)P(n-1) such pennants.
  • If the last number is 2, the preceding sequence must sum to n−2n - 2, which is an (n−2)(n-2)-pennant. There are P(n−2)P(n-2) such pennants.

Therefore, P(n)P(n) satisfies the Fibonacci recurrence:

P(n)=P(n−1)+P(n−2)for n≥3P(n) = P(n - 1) + P(n - 2) \quad \text{for } n \ge 3

Given initial conditions:

  • P(1)=1P(1) = 1 (sequence: (1))
  • P(2)=2P(2) = 2 (sequences: (2), (1, 1))
  • P(3)=3P(3) = 3 (sequences: (2, 1), (1, 1, 1), (1, 2))

Computing subsequent values:

  • P(4)=P(3)+P(2)=3+2=5P(4) = P(3) + P(2) = 3 + 2 = 5
  • P(5)=P(4)+P(3)=5+3=8P(5) = P(4) + P(3) = 5 + 3 = 8
  • P(6)=P(5)+P(4)=8+5=13P(6) = P(5) + P(4) = 8 + 5 = 13
  • P(7)=P(6)+P(5)=13+8=21P(7) = P(6) + P(5) = 13 + 8 = 21
  • P(8)=P(7)+P(6)=21+13=34P(8) = P(7) + P(6) = 21 + 13 = 34
  • P(9)=P(8)+P(7)=34+21=55P(9) = P(8) + P(7) = 34 + 21 = 55
  • P(10)=P(9)+P(8)=55+34=89P(10) = P(9) + P(8) = 55 + 34 = 89

Thus, the number of 10-pennants is 89.

Final answer

89

Common trap

Off-by-one errors in Fibonacci index (computing F10=55F_{10} = 55 instead of F11=89F_{11} = 89).

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2014 Computer Science and Information Technology (CS) Session 1
Question
59 of 65, printed as CS Q.49
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.