Question

Let ana_n be the number of nn-bit strings that do NOT contain two consecutive 1s. Which one of the following is the recurrence relation for ana_n?

Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2016 answer key

Solution

Classify nn-bit valid strings by their last bit to set up the linear recurrence relation.

Let ana_n denote the number of nn-bit binary strings with no consecutive 1s.

Consider the final bit of any valid nn-bit string:

  1. If the string ends in 0, removing the final 0 leaves a valid (n−1)(n-1)-bit string with no consecutive 1s. There are an−1a_{n-1} such strings.
  2. If the string ends in 1, the preceding bit must be 0 (since consecutive 1s are forbidden). Thus the string must end in the suffix '01'. Removing this suffix leaves a valid (n−2)(n-2)-bit string with no consecutive 1s. There are an−2a_{n-2} such strings.

Since every valid string either ends in 0 or ends in 01, by the rule of sum:

an=an−1+an−2a_n = a_{n-1} + a_{n-2}
Final answer

B

Common trap

Multiplying an−2a_{n-2} by 2, which would erroneously allow the preceding bit to be 1.

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

Source

Paper
GATE 2016 Computer Science and Information Technology (CS) Session 1
Question
12 of 65, printed as CS Q.2
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.