Question
Finding the kth smallest element. This time around, suppose we have data that consists of integer intervals [a, b] that represent the ordered sequence (a,
Finding the kth smallest element. This time around, suppose we have data that consists of integer intervals [a, b] that represent the ordered sequence (a, a + 1, a + 2, . . . , b).
Suppose we know that the intervals lie in the range [0, N]. Given [a1, b1], . . . , [an, bn] and an integer k, design an efficient algorithm that outputs the kth smallest number in the union of these intervals. Describe your running time in terms of n and N.
For example, suppose we are given [5, 25], [3, 10], [8, 12] then the union of these intervals is the sequence (3, 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 14, . . . , 25).Hence, the 10th smallest number is 8.
(Note: Do not explicitly compute the union of the intervals because it can contain an exponential number of elements compared to your input. Rather, ask yourself the following question: Given a number x, how do you efficiently determine the number of numbers in the union of the intervals that is smaller than x? How can you use the answer to this question and questions like it to determine the kth smallest element?)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started