partition a sequence of 2n real numbers so that

后端 未结 3 2058
深忆病人
深忆病人 2021-02-15 06:07

I\'m currently reading The Algorithm Design Manual and I\'m stuck on this exercise.


Take a sequence of 2n real numbers as input. Design an O(n log n) algorithm tha

3条回答
  •  抹茶落季
    2021-02-15 06:32

    I think I can prove this for a sequence with no duplicated numbers, and it should be a reasonably simple exercise for the reader to extend the proof to non-unique sequences.

    Pair x0, x2n together, then pair all other numbers according to an optimal solution.

    Now consider the pairing of (x0, x2n) against any other pair xy, xz from the optimal subset. x2n + either xy or xz will be greater than xy+xz and also x2n+x0, therefore the pairing of x2n, x0 was optimal.

    The proof now extends by induction to the pairing of X1, X2n-1, and further partitions of the subset, eventually producing the OP's pairing.

提交回复
热议问题