I have multiple ordered lists. Unfortunately, the order of the items isn't a simple alpha or numeric comparison, otherwise this is trivial. So what I have is something like:
List #1 List #2 List #3
groundhog groundhog easter
mothersday mayday mothersday
midsummer laborday halloween
christmas
And from this I can gather than groundhog < mothersday, but the relationship of groundhog and easter is unknown. I am guaranteed that the order of the items from list-to-list is self consistent. (i.e. that no matter which list it occurs in, easter is always before halloween)
But what I need is a new ordered list that represents each item in the other lists only once, that preserves all of the known relationships above:
groundhog
easter
mayday
mothersday
midsummer
laborday
halloween
christmas
However, the following list is also perfectly valid:
easter
groundhog
mothersday
mayday
midsummer
laborday
halloween
christmas
I'm looking for a fairly quick, general-purpose algorithm I can use to order N lists in this way. (Working C# code a plus, for sure, but not necessary.)
I have solution that works, but its O(N^2) and a dog with even modest data sets.