You can use a TRIE  ..  Structure can be something like this

struct trie
{
   int count; // no of occurences
   char *child[SIZE];
};

when ever u insert ( it will take just O(length) time) .. just increment
count by 1

For each query (also O(length) time) the no of occurrences of the word will
be count of the last character

Hope it helps


On Sat, Feb 27, 2010 at 5:35 PM, <piyushgoe...@gmail.com> wrote:

> Maintain a hash of word to freq. Keep adding words and incrementing their
> frequencies while reading the documents
>
>
> Pigol
>
>
> On Feb 27, 2010, at 5:10 PM, vijay <auvija...@gmail.com> wrote:
>
>  You have to count the occurances of all words in a document. You are
>> given a method chat * GetNextWord, that returns the next word from the
>> document.
>> - Which datastructure can be userd to achieve this
>> -
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to