Skip to content
Related Articles

Related Articles

Improve Article
GATE | GATE-CS-2015 (Set 1) | Question 65
  • Last Updated : 20 Feb, 2015

Let an represent the number of bit strings of length n containing two consecutive 1s. What is the recurrence relation for an?
(A) an–2 + an–1 + 2n–2
(B) an–2 + 2an–1 + 2n–2
(C) 2an–2 + an–1 + 2n–2
(D) 2an–2 + 2an–1 + 2n–2


Answer: (A)

Explanation: Simple Solution
One way to solve this is to try for small values and rule out options.

a0 = 0  
a1 = 0  
a2 = 1  ["11"]
a3 = 3  ["011", "110", "111"] 
a4 = 8  ["0011", "0110", "0111", "1101",
                    "1011", "1100", "1110", "1111"]

If we check for a3, we can see that only A and C satisfy the value. Among (A) and (C), only (A) satisfies for a4.

Another Solution (With Proof)

A string of length n (n >= 2) can be formed by 
following 4 prefixes

1) 11 followed by a string of length n-2
2) 00 followed by a string of length n-2
3) 01 followed by a string of length n-2
4) 10 followed by a string of length n-2

Number 1 has already two consecutive 1's so number 
of binary strings beginning with number 3 is 2n-2
as remaining n-2 bits can have any value.

Number 2 has two 0's so remaining n-2 bits must have
two consecutive 1's. Therefore number of binary strings
that can be formed by number 2 is an-2.

Number 3 and Number 4 together form all strings of length
n-1 and two consecutive 1's.


Quiz of this Question

Attention reader! Don’t stop learning now. Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :