Question

Let ana_n represent the number of bit strings of length nn containing two consecutive 1s. What is the recurrence relation for ana_n?

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2015 answer key

Solution

Derive the recurrence relation by partitioning bit strings of length n based on their ending bit patterns.

Let ana_n denote the number of bit strings of length nn containing two consecutive 1s.

We partition any valid string of length nn into mutually exclusive cases based on its suffix:

  1. Ends in 0: The last bit is 0, so the first n−1n-1 bits must contain two consecutive 1s. There are an−1a_{n-1} such strings.
  2. Ends in 01: The last two bits are 01, so the first n−2n-2 bits must contain two consecutive 1s. There are an−2a_{n-2} such strings.
  3. Ends in 11: The last two bits are 11. Since this suffix already provides two consecutive 1s, the prefix of length n−2n-2 can be ANY arbitrary bit string. The number of arbitrary bit strings of length n−2n-2 is 2n−22^{n-2}.

These three cases are mutually exclusive and collectively cover all valid bit strings of length nn.

Summing the counts gives the recurrence relation:

an=an−1+an−2+2n−2.a_n = a_{n-1} + a_{n-2} + 2^{n-2}.

This matches option A.

Final answer

A

Common trap

Double-counting strings by adding 2^(n-2) to overlapping subcases.

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

Source

Paper
GATE 2015 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.