HW 5
HW 5
4. You have have found n id cards with magnetic strips that each encodes some id number. Due to
security precautions, you do not have any way to read the id number off of a card directly. However,
you do have a tester machine that will read two cards and tell you whether they have the same id
number encoded on them.
Give an O(n log n)-time algorithm to test whether some subset of more than n/2 cards have the same
identifier encoded on them.
5. 02-713 only! You want to draw a two-dimensional skyline like the following:
y4
h5
h4
y3
h6
h1
y5
y1
y2
h2
h3
l1
l 2 r1
l3
r3 l 4
r2
r4
l4
l5
r4
r5
x1
x2
x3
x4
x5
x6
x7
You are given a list of the building x-coordinates and their heights:
(l1 , h1 , r1 ), (l2 , h2 , r2 ), . . . , (ln , hn , rn )
This list will be sorted in increasing order of left-most x-coordinate. Sketch an O(n log n) algorithm
to produce the skyline line to draw in the format:
x1 , y1 , x2 , y2 , x3 . . .
meaning that at x1 we draw a building at height y1 until x2 at which point we draw a line up or down
to high y2 and then continue horizontally until x3 and so on.
Note that for this problem, you need only sketch the main ideas, not provide as detailed a discussion
as typically.