i think that if you implement the elements of a string in set you can find its children easily (specially if you map each set to the real strings) in O( n . max length of a string . d) where n is the number of strings and d is running time of set.delete() after making the graph since the maximum chain of ancestors starting from a node is unique so you can find the overall longest chain of ancestors in O( n ) using memoization or dp
plz correct me if I'm wrong On Sun, Jun 20, 2010 at 2:50 PM, sharad <sharad20073...@gmail.com> wrote: > Given a dictionary of words, find out the longest chain of 'ancestors' > in it. Ancestors are defined in the following way: A word is said to > be the parent of another word if > 1) It is a valid word in the dictionary > 2) It can be obtained by deleting one character of the word and > permuting the remaining characters. > eg. run is a parent of urns > A possible chain of ancestors could be: > a > an > ban > nabs > bands > This chain is of length 4. What is the length of the longest chain in > a given dictionary? > > -- > 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.