0

This is a theory question so I'm going to use pseudo code.

I have a list of objects that I need to transform into another list.

I implemented the Levenshtein algorithm, and that works just fine, but I need to preserve the objects, and not create new ones. I can brute force it but Id rather find a non O(n*m) way to do this.

[obj1,obj2,obj3] -> [obj1,obj4,obj5,obj2,obj6,obj3]

obj1,obj2,obj3 have to be the same object where the rest are newly created objects.

Anybody know a good algorithm for this?

Chris Dargis
  • 5,891
  • 4
  • 39
  • 63
busbina
  • 549
  • 1
  • 7
  • 19
  • 1
    This question is impossible to answer in pseudocode, because the answer depends on the features of your language. The answers for C++ and Java will be very different. – Sergey Kalinichenko Aug 17 '12 at 17:04
  • Are the objects in your question strings. What should the intermediate objects look like, are they the steps with edit distance 1? – cmh Aug 17 '12 at 17:12
  • No the objects are complex classes. All edit distances are 1. These are small lists of ordered user content. I'm doing this in C# and the lists are Lists of the class we made. – busbina Aug 17 '12 at 17:49

1 Answers1

1

You could use pattern flyweight, to do that you'll need to maintain created objects in the cache. Strings in java is a good example of this pattern.

Rrr
  • 1,747
  • 3
  • 17
  • 22
  • I see how this would work. I end up going through each list only once. Ill implement it and get back. THANKS!! :) – busbina Aug 17 '12 at 18:22