Number of possibilities to change a specific amount of characters in a word

48 Views Asked by At

Imagine there is an alphabet a that contains |a| characters to choose from. Furthermore, there is a word w that consists of |w| characters of said alphabet (such a word is just a random combination of characters, it doesn't need to have a real meaning in a natural language).

I'm wondering how many possibilities there are to exchange exactly n characters of a particular, given word with other characters from the alphabet (there are |a|-1 characters to choose from when replacing each character since a character should not be replaced with itself).

Example:

a = { A, B, C, D }

w = BCADDBACADCBAA

n = 3

So the goal is to find out the total amount of variations of w that differ in exactly 3 places.

My math background is not very strong, but I came up with the following naive approach:

  • The number of ways (let's call it "iterations") to choose n characters from w to replace is binom
  • In every iteration, each of the n characters can be replaced with one of |a|-1 characters, which leads to power possibilities

So isn't the amount of total variations just the following?

total