I have a totally ordered set S and I'd like to re-order it based on a partial ordering P.
If set S looks like [A, B, C, D, E] where A < B, B < C, and so on. And set P looks like [A, E, B]. Then I'd like to create a new ordered set S' with ordering [A, E, B, C, D].
The idea being that S' is based on S, with minimal changes made in order to make it conform to the new ordered relationships introduced by P. If P had been [E, B, A], then S' could be [E, B, A, C, D] or [C, D, E, B, A], but the first would be preferred because it preserves more of the original ordered relationships than the latter (5: B < C, B < D, A < C, A < D, C < D) vs (3: C < D, C < E, D < E).
Is there an efficient algorithm that does this? Or any area of research I could look into?