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)
GATE 2025 CS1 Q.30: solution and answer
Answer and solution
ANSWER
The number of such strings is 195.
Official answer: 195Source: Official answer key, GATE 2025 CS1 (IIT Roorkee)
Count the complement: strings of length 5 over in which no two adjacent symbols are equal. Then answer total complement.
Total strings of length 5 over 3 symbols: .
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.
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.
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
- GATE 2023 CS Q.48 · MCQ · 2 marksLet U = 1, 2,, n, where n is a large positive integer greater than 1000.
- GATE 2022 CS Q.32 · NAT · 1 markThe number of arrangements of six identical balls in three identical bins is.
- GATE 2020 CS Q.42 · NAT · 2 marksThe number of permutations of the characters in LILAC so that no character appears in its original position…
