GATE / CS ARCHIVE

GATE CSE 2025 SET 1 / QUESTION 30

Counting ternary words with adjacent repeats

Discrete Mathematics · Combinatorics & Counting · Full GATE CSE 2025 Set 1 paper

GATE 2025 Set 1, Q30 1 mark · NAT
Report issue

Combinatorics & Counting

Question 30, GATE 2025: Over alphabet {a,b,c}, count the length-five strings containing at least one adjacent equal pair aa, bb or cc.
Tap to enlarge
Answer & solution

Official answer: 195

Approach: Count the complement, because counting each repeated-pair position directly would count some strings multiple times.
There are three choices independently at each of five positions, so there are 35=243 strings in total. A string with no equal adjacent symbols has 3 choices for its first symbol. At each of its remaining four positions, the immediately previous symbol is forbidden and the other two are allowed. This gives 3×24=48 strings without adjacent repeats.
Every string either has an adjacent equal pair or has none, and these categories are disjoint. Subtracting the latter from the total gives 243−48=195.
For example aaaaa has four repeated-adjacency positions, but it must count as just one string. Complement counting handles such overlaps automatically. The condition is “at least one”, so strings with two, three or four equal adjacent pairs all remain included in 195.

Original paper, page 30 · Answer key