Hey, what's going on guys, my name is Zero Davila, welcome back
to Save Our System IT. Today we will write an anagram generator,
and I will familiarize you with one of the algorythms that can
helps us implement this by checking every posible permutation
of a sequence of characters, also known as a string. Using the
algorythm we will generate the anagrams in a lexicographical
order. The results will have a root, so first they will have a
character, and then after we will have all possible permutations
that start with that character, then it will continue in a
similar fashion until all characters in the string are used.
Because our string only has 3 characters, the number of possible
permutations are 3! / 1!. If one of the characters would have
had a duplication, the number of possible permutations would be
4! / 2!. So for ABC we have 3 X 2 X 1, meaning 6. If the input
would have been AABC, the counter for the letter A would start
off at 2, and the number of possible permutations would have
been 4! / 2! meaning 12. If our input would have been AABBBC
the number of possible permutations is 6! / 2! * 3! which is 60,
because we encounter A two times, and B three. The counter for
each character, that we will keep track off with an array called
count, show's if the character is available or not. A character
is available only if it has a counter greater than 0. Our
counters are only either 1 or 0, but that's because no character
was duplicated. When the counter for our 3 character string is
0, 0, 0, it means that the array we keep our result in is full,
so we will just add it to a result list to be printed along with
the other results. The algorythm will go from left to right and
it will take the first available character, meaning that its
counter is greater than 0. Then we will place the character in
it's coresponding position in the array that contains the whole
result, by checking what recursion level we're at in the tree.
If we have a three character string, we will have three recursion
levels. If we're at the first node in the tree, meaning position
0, then we will place the first available character at index 0
in the result array. And then, because the algorythm is recursive
we will do the exact same thing after we decrement the counter
for that character, because we already used that character. When
we go back up the tree, we restore the counter, and search for
the next available counter to the right, to start off another
branch.
Watch video How to build a anagram generator online without registration, duration hours minute second in high quality. This video was added by user SOSIT 22 January 2017, don't forget to share it with your friends and acquaintances, it has been viewed on our site 743 once and liked it 7 people.