lundi 21 septembre 2020

How to optimize the comparison of two lists to reduce the number of updates

I am working on an algorithm to compare to lists of ranges. The setup is simple, but the algorithm is getting more and more complex. I'm afraid I might be reinventing the wheel here so I thought I would ask the community if this sounds like any design patterns that have already been figured out.

I have two lists to compare. Each list contains a Boolean - Yes/No, and a range of numbers. Here's a visual:

List 1:

Key   Value     Range Start    Range End
-----------------------------------
A1    Y         1              5
A2    N         9              11
A3    Y         13             15

List 2:

Key   Value     Range Start    Range End
-----------------------------------
B1    Y         3              7
B2    N         9              14

The goal: to identify the optimal number of changes necessary to make list 1 cover the same ranges as list 2. In this case it would be: Update A1 to start at 3 and end at 7, Update A2 to end at 12, Update A3 to end at 14. I think this is similar to what a text-comparison algorithm might do.

I've created a rats nest of a flow chart to model this and I'm only half done. Looking forward to any suggestions that would point me in a better direction.

Aucun commentaire:

Enregistrer un commentaire