No ABs in this string

A string of n n characters is made from the characters A \text{A} , B \text{B} , and C \text{C} .

Let G n G_n be the number of such strings of n n characters which contain no instance of AB \text{AB} (in that order).

Write a recurrence relation for G n G_n .

G n = 3 G n 1 1 G_n=3G_{n-1}-1 G n = 3 G n 1 G n 2 G_n=3G_{n-1}-G_{n-2} G n = 3 G n 1 G_n=3G_{n-1} G n = G n 1 + G n 2 G_n=G_{n-1}+G_{n-2}

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Andy Hayes
Jul 7, 2016

There is 1 1 string which contains 0 0 characters (an empty string), and it does not contain AB \text{AB} . Therefore, G 0 = 1 G_0=1 .

There are 3 3 strings which contain 1 1 character: A , B , C \begin{array}{ccc} \text{A}, & \text{B}, & \text{C} \end{array} . None of these contain AB \text{AB} . Therefore, G 1 = 3 G_1=3 .

To obtain the number of strings for n = 2 n=2 , append an A \text{A} , B \text{B} , or C \text{C} to each of the previous strings.

AA , AB , AC , BA , BB , BC , CA , CB , CC \begin{array}{ccc} \text{AA}, & \color{#D61F06}{\text{AB}}, & \text{AC}, \\ \text{BA}, & \text{BB}, & \text{BC}, \\ \text{CA}, & \text{CB}, & \text{CC} \\ \end{array}

The number of strings is 3 3 times as much as the previous number of strings. However, note that 1 1 of those strings contains AB \text{AB} . It occurred by appending a B B to one of the previous strings which ended in an A \text{A} . Thus, G 2 = 8 G_2=8 .

To obtain the number of strings for n = 3 n=3 , append an A \text{A} , B \text{B} , or C \text{C} to each of the previous strings.

AAA , AAB , AAC , ACA , ACB , ACC , BAA , BAB , BAC , BBA , BBB , BBC , BCA , BCB , BCC , CAA , CAB , CAC , CBA , CBB , CBC , CCA , CCB , CCC \begin{array}{ccc} \text{AAA}, & \color{#D61F06}{\text{AAB}}, & \text{AAC}, \\ \text{ACA}, & \text{ACB}, & \text{ACC}, \\ \text{BAA}, & \color{#D61F06}{\text{BAB}}, & \text{BAC}, \\ \text{BBA}, & \text{BBB}, & \text{BBC}, \\ \text{BCA}, & \text{BCB}, & \text{BCC}, \\ \text{CAA}, & \color{#D61F06}{\text{CAB}}, & \text{CAC}, \\ \text{CBA}, & \text{CBB}, & \text{CBC}, \\ \text{CCA}, & \text{CCB}, & \text{CCC} \\ \end{array}

The number of strings is 3 3 times as much as the previous number of strings. However, note that 3 3 of those strings contain AB \text{AB} . Those occurred by appending a B B to one of the previous strings which ended in an A \text{A} . Thus, G 3 = 21 G_3=21 .

Without writing out the next case, predict how many there will be. There will be 3 3 times as many strings as G 3 G_3 , but some number will be subtracted that contain AB \text{AB} . The number that is subtracted will be the number of strings that previously ended in A A . The number of strings that previously ended in A A is 8 8 . This the same as G 2 G_2 .

G 4 = 3 G 3 G 2 G_4=3G_3-G_2

In terms of n n , this is:

G n = 3 G n 1 G n 2 G_n=3G_{n-1}-G_{n-2}

The solution is also equal to 2G(n-1)+G(n-2)

Prayas Rautray - 3 years, 9 months ago

Log in to reply

Sorry sorry, miscalculated. Please ignore.

Prayas Rautray - 3 years, 9 months ago

What about the cases in n=3, when the string is ABA, ABB or ABC? The answer comes out to be correct in either case but shouldn't there be 27 cases (after including the ones that I mentioned)? Then we subtract 6 (AAB, BAB, CAB, ABA, ABB, ABC) to get 21?

Sarthak Khattar - 3 years, 3 months ago

Note that the letters in red for n=2 (AB) are not carried to the stage for n=3, since this would result in invalid sequences only. Hence the discrepancy of three cases that you mention.

David Cross - 1 year, 10 months ago

the answer is right but you did not explain the logic. Doing questions like this may hold for the 1st 5-6 cases, but may be invalid later on . It was based on sheer observation !!!

Prabhnoor Singh - 1 year, 2 months ago

This is not the proof but a verification .

Amar datta - 1 year ago
Yugesh Kothari
Aug 25, 2016

Proceeding completely logically, Suppose I make this String by writing letters on a large sheet from left to right and that I have already written n n characters. For the n + 1 t h n+1^{th} character, there are essentially three possibilities ( A,B or C ). So 3 G n 3G_{n} . But wait, what if the n t h n^{th} character was A ? Well, we simply subtract that case. So suppose we have written down n 1 n-1 characters and the n t h n^{th} character is fixed at A . Now, the unfavourable case was that the n + 1 t h n+1^{th} character in this case be B . Hence, G n 1 G_{n-1} .

Therefore, the relation - G n + 1 = 3 G n G n 1 G_{n+1}=3G_{n} - G_{n-1}

Well Explained !!

Amar datta - 1 year ago

since there are Gn-1 strings which if end with a can be unfavourable hence we subtract those Gn-1 cases

Kanishk Anand - 9 months, 3 weeks ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...