ProgrammingVery hardGATE CS · Campus placements

How many binary strings of length 5 contain no two adjacent 1s?

  1. A. 8
  2. B. 11
  3. C. 13
  4. D. 21

Correct answer: C. 13

Let f(n) count valid strings of length n, with f(1) = 2 and f(2) = 3, then f(n) = f(n-1) + f(n-2). This gives 2, 3, 5, 8, 13 for n = 1 to 5, so f(5) = 13.

More C Programming questions

Exams that ask this topic