hi, This is a very famous question which was asked in my google and yahoo interviews. There is a very good ole data structure designed for this purpose called TRIE data structure. This will solve the problem. On 2/15/07, aakash mandhar <[EMAIL PROTECTED]> wrote: > > And from my experience as an interviewer and as a person appearing for an > interview this is the answer I would expect, but would love to hear other > solutions and the trade offs between a trie and a b-tree and as is always > the case, usecase drives the selection of datastructure. > > If you need faster retrievals trie is the way to go. > If you want to overcome the overheads of a trie (mainly the space > utilization) try hashing the names or use a B Tree. > > Regards, > Aakash > > On 2/15/07, aakash mandhar <[EMAIL PROTECTED]> wrote: > > > > I would recommend using a trie, and a list of all numbers for the same > > name at a terminating point of the trie. > > > > Regards, > > Aakash > > > > On 2/14/07, Karthik Singaram L <[EMAIL PROTECTED]> wrote: > > > > > > It does depend on the size of the problem you have in mind. Tries can > > > be expensive for names depending on the sparseness of the data set, you > > > may > > > waste a lot of pointers. If you use B-Trees they may be good in such > > > cases. > > > B-trees are generally a bit better when it comes to data stored in a disk > > > with the index alone being cached in memory. > > > > > > > > > > > > > > > > > > > > > > > >
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---