Looks like we finally jump out from the Tree series, this week our topic is Anagrams, it seems really fun but complicated. Basically the anagram funcion is rearrange a given word and find the actual English word from a given word list such as from "deposit" to "topside" if "topside" is in the word list.
The function is base on recursion but have two different ideas, one call Permutation Approach and other call Signiture Approach. Permutation rearrange the given word to all possible value and compare if there are some word contains in the word list; Signiture is reorder the given word and all word from given word list into the alphabetical order and find if some word in list has the same.
To choose wich idea is depends on length of the word you try to anagram, Permutation works efficiently when the word is short such as "horse", but it take really long time when given long word since it need to rearrange to all possible order, in this case we use Signiture instead.
没有评论:
发表评论