Блог пользователя derAdler

Автор derAdler, история, 8 лет назад, По-английски

hello guys, i know this might sound silly. I was just studying trie the other day and i wanted to ask that why do we use it at all we can maintain a directed graph of 26*26 where G[i][j] corresponds to whether j is a child of letter i. Could somebody explain how i am wrong with an example. Any help would be appreciated. Thanks a lot in advance.

  • Проголосовать: нравится
  • -24
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

How would you represent the following input strings in your trie?

1- ham 2- ed 3- me

a trie should support looking up a word in linear time, would you report found or not found for the string "hamed" ??

»
8 лет назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

Consider aba, how would you store it? The directed graph would contain a cycle which you cannot determine the length of the string.

Then you could say "let's store a number 3 at a so that we know there is a string of length 3". But then this won't work: abaca (no other strings) since you cannot distinguish ababa, abaca, acaba and acaca (all are length 5).