Skip to content
Official PYQ · 2008

GATE CS 2008 Q78 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

Let xnx_n denote the number of binary strings of length nn that contain no consecutive 00s.

Which of the following recurrences does xnx_n satisfy?

Choose one option
View worked solution

Answer: D

To find the recurrence relation for xnx_n, the number of binary strings of length nn containing no consecutive 00s, we can analyze the structure of any valid string of length nn based on its ending character:

  • Case 1: The string ends with '1'
    If the last character is '1', the preceding n−1n-1 characters can be any valid binary string of length n−1n-1 with no consecutive 00s.
    The number of such strings is xn−1x_{n-1}.
  • Case 2: The string ends with '0'
    Since the string cannot contain consecutive 00s, the character immediately preceding the last '0' must be '1' (for n≥2n \ge 2). Thus, the string must end with '10'.
    The remaining prefix of length n−2n-2 can be any valid binary string of length n−2n-2 with no consecutive 00s.
    The number of such strings is xn−2x_{n-2}.

Since these two cases are mutually exclusive and exhaustive, we sum them to get the total count:

xn=xn−1+xn−2for n≥2x_n = x_{n-1} + x_{n-2} \quad \text{for } n \ge 2

Verification with small values:

  • For n=1n = 1: Valid strings are 0, 1   ⟹  x1=2\implies x_1 = 2.
  • For n=2n = 2: Valid strings are 01, 10, 11   ⟹  x2=3\implies x_2 = 3.
  • For n=3n = 3: Valid strings are 010, 011, 101, 110, 111   ⟹  x3=5\implies x_3 = 5.

Using the recurrence relation: x3=x2+x1=3+2=5x_3 = x_2 + x_1 = 3 + 2 = 5, which perfectly matches the manual count.

Therefore, the correct option is D.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions