Data Structures & AlgorithmsVery hard

For a binary string with no three equal consecutive bits, why is a run-length description convenient for counting?

  1. A. Runs can have any length, so no structure exists.
  2. B. Every string of length 6 has exactly three runs.
  3. C. The count equals 2 to the power of the number of runs.
  4. D. Each run has length 1 or 2, and the bit value alternates between consecutive runs, so the count follows a simple recurrence.

Correct answer: D. Each run has length 1 or 2, and the bit value alternates between consecutive runs, so the count follows a simple recurrence.

Restricting runs to length 1 or 2 with alternating values turns the count into a recurrence over the number of runs. This is a standard run-length DP.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic