King Yéméchan has given his royal mathematician
Yséconthé a list of treasures that belong to neighbouring countries. For
each treasure, the list specifies
- How much the treasure is worth.
- How easy it would be for Yprantou (the royal thief) to acquire this
treasure.
Each treasure can thus be represented by a point in the plane: the x
coordinate represents how much the treasure is worth, and the y coordinate is
the difficulty of stealing that treasure (where a higher y coordinate
corresponds to a treasure that is easier to steal). Given two such points, we will say
that a point q = (q.x, q.y) dominates the point p =
(p.x, p.y) if q.x ≥ p.x and q.y ≥ p.y. That
is, q lies to the right of and above p, as illustrated in picture on
the left.
Clearly, a point p that is dominated by a point q is of no
interest, since q is both worth more and easier to steal than p.
Hence, to help you reach a decision, you only need to worry about locations that
correspond to maximal points: those that no other point dominates.
For instance, in the picture on the right, the
points p3, p4 are p6 are
maximal, as you can see from the fact that their upper-right quadrants are empty.
- Describe a simple algorithm that takes as input a set P of points, and a
point q, and returns all points of P that q does not
dominate.
- Describe an efficient divide-and-conquer algorithm that takes as input a set
P of points, and returns the list of treasures that Yprantou might be asked
to steal first (that is, all maximal points of P). Hints:
- Start by deciding how many subproblems you will have, and which point(s) will
belong to each subproblem. You can not simply assign points to the subproblems
randomly.
- If a point is maximal in one subproblem, is it automatically maximal
in P? Does it matter which subproblem the point belongs to?
- When you are combining the solutions to your subproblems, you should choose a
point carefully in one subproblem, and then call your algorithm from part (a)
exactly once.
- Analyze the worst-case running time of your algorithm from (b).