title: Using a trie data structure on word occurance
body: <p><em>This question is language independent and is more about understanding how to implement the trie or whether tries would be appropriate for what my program is suppose to do</em>. 
  Say I have a string of text like this.</p>
  
  <pre><code>string= "a tale about an ant and an android";
  </code></pre>
  
  <p>The corresponding trie for "a" looks like this</p>
  
  <pre><code>      a(7)      
       /    \     
      b(1)  n(4)
      /     /   \
    o(1)  t(1)  d(2)
    /              \
   u(1)            r(1)
   /                 \
  t(1)               o(1)
                       \
                       i(1)
                         \
                          d(1)
  </code></pre>
  
  <p>and I want to find the number of occurrences for each word. Although "a" appears 6 times in the text there is only one instance where it is used as a word. The same rule applies for "an" &amp; "and".</p>
  
  <p>I want my final frequency counter to look like this:</p>
  
  <p>a: occurs 1 time not 7
  an: 2
  and: 1
  and so on..</p>
  
  <p>How is it possible for me to record the counts of full words?  </p>
  
  <p>I'm working in php trying to process a load of text and have visited <a href="https://stackoverflow.com/questions/4670417/count-word-frequency-in-a-text">this question</a> and it is not what I am looking for. Performance is important but memory efficient is more preferable since I am parsing say a trillion words. Thanks and I appreciate your input.</p>