Guest User

Untitled

a guest
Mar 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. L = length of number
  2. N = number of words
  3. M = length of each word
  4.  
  5. Here's a trie. It has 11 nodes.
  6.  
  7. root
  8. / | \
  9. a b d
  10. / | / \ / | \
  11. a b a d a b d
  12.  
  13.  
  14. Here's a number: 2222222... (L 2's)
  15.  
  16. According to the traversal algorithm
  17.  
  18. a. Look for ('a', 'b', 'c') at the start of the trie.
  19. b. If the relevant node exists, repeat the procedure from that node.
  20. c. If it doesn't exist, terminate.
  21.  
  22. So in this example, we go to nodes (a) and (b). Then from there we go to nodes (aa), (ab), and (ba).
  23. After that, we've terminated all paths. The number of traversals is not dependent on L -- it's capped by the number
  24. of nodes in the trie.
  25.  
  26. A bit more of a generic explanation:
  27. The only place where we do a recursive call in the algorithm is b.
  28. In order to make a recursive call at (b), a node must exist in the trie.
  29. However, we can also show that each node in the trie will be visited at most once:
  30. - Each node in a trie corresponds to a unique prefix
  31. - Each path in the number traversal corresponds to a unique prefix
  32. --> So two paths in the number traversal can't visit the same node.
  33.  
  34. As a result, the number of recursive calls is no more than the number of nodes on the trie.
Add Comment
Please, Sign In to add comment