How do i find permutation of a word containing a certain word

discrete mathematicspermutations

We can assume the word has all unique characters.
For example, ABC's permutations are ABC, ACB, BAC, BCA, CAB, CBA. How would I find the number of permutations of ABC containing for example, AB? What is its relation to the original word?

Best Answer

If you want to know how many times the substring AB appears in the set of all permutations of the string ABC, simply consider AB as a whole (as if it was a single letter). So instead of 3!, it would be 2! = 2 times.

For example, if you have 3 boxes A, B, C and you want to generate all the permutations of the boxes where the box B is immediately after the box A, then you simply drag A and B at the same time, as if they were a single box. That's the reasoning.

Related Question