Anagram algorithm using a hash table and / or trying

For some time now I searched the Internet for steps to search for all anagrams of a string (word) (i.e. the command creates the word manual) using a hash table and three. All I found here on SO is to verify that 2 words are anagrams. I would like to take one more step and find the algorithm in English so that I can program it in Java.

For instance,

  • Scroll through all the characters.
  • For each unique insertion of characters into a hash table.
  • etc.

I do not need a complete program. Yes, I'm training in an interview. If this question arises, I will know it and I know how to explain it, and not just remember it.

0
source share
3 answers

- , - " " ():

" ( ), ( )"

, , (word), : (sorted_word, word), .

, , , .

( ):

mate
tame
mote
team
tome

" " ( ):

aemt, mate
aemt, tame
emot, mote
aemt, team
emot, tome

" " ( ):

aemt, mate
aemt, tame
aemt, team
emot, mote
emot, tome

"" → "aemt"

aemt, mate
aemt, tame
aemt, team

hashtables/try, , . -, 2 k- . , . - , , trie.

+4

, , .

( ) :

:

a → 2 b → 3 c → 5 d → 7

.., a..z 26 .

, " ". TEAM TAME . , , .

, , . , , nlog (n) .

+3
  • String to char[]
  • char[]
  • String char[]
  • HashMap<String, List<String>>
  • insert the current source into the list of related values

for example for

car, acr, rca, abc he would have

acr: car, acr, rca
abc: abc
0
source

All Articles