Number of permutations between strings -


for word "bookkeeper". it's sorted representation "beeekkoopr" how can find different permutations of word between "beeekkoopr" , "bookkeeper"?

similar example:

for "bbaa"

aabb - 1 abab - 2 abba - 3 baab - 4 baba - 5 bbaa - 6 

6 - 1 = 5 there 5 words before "bbaa"

"beeekkoopr" number 1. "bookkeeper" distance away. i'm not sure how go believe combinatorics problem , don't have experience subject.

you must understand lexicographic order, if not already.

the lexicographic order way, alphabetical order of words based on, alphabetical order of letters composed off. example of order of words given in dictionary. example in dictionary, word "verification" appears before "verify". because, first letter different in both words 6th letter, , since 'i' comes before 'y' in alphabet, "verification" appears before "verify".

in order understand permutations, can think of lexicographic order increasing numerical order, same alphabetic order letters in english alphabet. example, permutations of numbers 1,2 , 3 in lexicographic order 123, 132, 213, 231, 312, , 321. example given you, "bbaa", 6 permutations of a,a,b , b in lexicographic order are: aabb, abab, abba, baab, baba , bbaa.

all permutations of letters, b, e, e, e, k, k, o, o, p , r, in lexicographic order, start "beeekkoopr" , ends "rpookkeeeb". permutation "bookkeeper" somewhere in between "beeekkoopr" , "rpookkeeeb".

in short problem posed problem find permutations of given entities (alphabets or numbers or else defined order) in lexicographic order. has been studied problem more thousand years. there many ways generate permutations. if search web while know that. recommend read "the art of computer programming", donald knuth, in-depth discussion.

one classical algorithm based on finding next permutation in lexicographic ordering, if exists, , keep on doing until last permutation. found useful algorithm toronto programer, see link details. python comes useful functions solve same problem.

going example, have start "beeekkoopr", first permutation in lexicographic order , keep on finding next permutation in lexicographic order, until find all.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -