I think one way we can do it is to sort all the names. And then do the linear scan to find the distinct names and their corresponding count.
Another way is to maintain a hash map. Check for each name if it already exists in the map. If it exists, simply increase the counter by 1 otherwise insert in hash map with counter 1. On Fri, Oct 15, 2010 at 1:18 PM, tech rascal <[email protected]>wrote: > u can do it by making binary search tree and each node should has 2 data > parts i.e, name and count. Whnevr u encounter the same name, update the > count of that corresponding node else keep on extending the tree. > > > On Fri, Oct 15, 2010 at 7:00 AM, Kumar S <[email protected]> wrote: > >> Q : A file has list of names. We need an algorithm to find the number each >> names repeats in that list. NOT case sensitive >> >> Example... >> >> namefile.txt has the content...... >> >> bob >> abi >> jack >> ram >> jim >> tim >> joey >> riya >> kris >> bob >> kris >> ram >> jack >> joe >> joe >> joey >> bob >> bob >> bob >> kris >> joe >> >> >> this has more than 32000 in the list.. not limited number . >> >> Output : must have the distinct names and the count against them.. >> >> Appreciate your inputs. >> >> Thanks n have a good one >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<algogeeks%[email protected]> >> . >> 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
