Assuming that you cannot have any letter repeated more than 15 times.

Create a struct of 26, 4 bit bitfields. This is going to take 26x4 bits
or 13 bytes of memory.

Use this structure to store the character count of each character of
the first string.

Now proceed to the second string and for each character, decrease it's
corresponding character count by 1 if it is greater than 0. If it is 0
then the second string is not a permutation of the first string.

At the end of processin the second string check whether each caracter
count is 0. If they all are 0 then the strings are permutations of one
another.

Of course you can modify the algo to accomodate higher maximum
character counts. In any case the time required is O(n) and space
required is 26 x ceiling ( log ( maximum_individual_character_count,
base=2) ) bits.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to