Question: Consider a sorting problem in which we do not know the numbers exactly. Instead, for each number, we know an interval on the real line
Consider a sorting problem in which we do not know the numbers exactly. Instead, for each number, we know an interval on the real line to which it belongs. That is, we are given n closed intervals of the form [ai, bi], where ai ≤ bi. We wish to fuzzy-sort these intervals, i.e., to produce a permutation 〈i1, i2, . . . ,in〉 of the intervals such that for j = 1, 2, . . . ,n, there exist cj ∈ [aij , bij] satisfying c1 ≤ c2 … cn.
a. Design a randomized algorithm for fuzzy-sorting n intervals. Your algorithm should have the general structure of an algorithm that quicksorts the left endpoints (the ai values), but it should take advantage of overlapping intervals to improve the running time. (As the intervals overlap more and more, the problem of fuzzy-sorting the intervals becomes progressively easier. Your algorithm should take advantage of such overlapping, to the extent that it exists.)
b. Argue that your algorithm runs in expected time Θ(n lg n) in general, but runs in expected time Θ(n) when all of the intervals overlap (i.e., when there exists a value x such that x ∈ [ai, bi] for all i). Your algorithm should not be checking for this case explicitly; rather, its performance should naturally improve as the amount of overlap increases.
Step by Step Solution
3.28 Rating (157 Votes )
There are 3 Steps involved in it
Answer a We sort the left endpoints and their corresponding right endpoints separately Lets call thi... View full answer
Get step-by-step solutions from verified subject matter experts
