IAE Academy

GATE 2025 CS1 Q.30: solution and answer

GATE 2025 · CS1Q.30 · 1 mark · NAT

Let be the set of all ternary strings defined over the alphabet . Consider all strings in that contain at least one occurrence of two consecutive symbols, that is, "aa", "bb" or "cc". The number of such strings of length 5 that are possible is ______. (Answer in integer)

See the question in the paper

Answer and solution

ANSWER

The number of such strings is 195.

Official answer: 195Source: Official answer key, GATE 2025 CS1 (IIT Roorkee)

  1. Count the complement: strings of length 5 over in which no two adjacent symbols are equal. Then answer total complement.

  2. Total strings of length 5 over 3 symbols: .

  3. A string has none of "aa", "bb", "cc" exactly when every symbol differs from the one before it. The first symbol has 3 choices. Each later symbol must differ from its predecessor, so it has 2 choices.

  4. Complement count . Check on length 2: the formula gives strings with no repeat (ab, ac, ba, bc, ca, cb), and strings (aa, bb, cc) do contain a repeat, which is correct.

  5. Strings with at least one of "aa", "bb" or "cc" .

KEY IDEA

Count the complement. Strings with no two equal adjacent symbols number , because each new symbol has exactly 2 choices that differ from the previous one. Subtract this from .

WATCH OUT FOR

Counting strings containing "aa", "bb" or "cc" directly and adding the three counts. This double-counts strings that contain more than one repeat, such as "aabbc". Another slip is to allow 3 choices for every position of the complement instead of 2 for positions after the first.

From the GATE 2025 CS1 paper. Every question of this paper · Download the full paper · All 6 Counting questions, with notes

More Counting questions