GATE Computer ScienceHardGATE CS (PYQ pattern)
The closed intervals [1,4], [2,6], [3,5], [7,10], [8,12], [9,11], [13,15], [5,8], [10,14], [0,2] are given. What is the minimum number of points on the line such that every interval contains at least one chosen point?
- A. 4
- B. 3
- C. 5
- D. 6
Correct answer: A. 4
Greedy: sort by right endpoint and pick the right endpoint of the first uncovered interval: points 2, 5, 10, 15 (the last for [13,15]). A brute force over all 3-point sets confirms that fewer than 4 points cannot stab all ten intervals.
More Algorithms questions
- From index 0 of the array [3, 1, 4, 1, 2, 1, 1, 5, 2, 1, 1, 3, 1, 2, 1] you may jump forward at most a[i] positions from index i. What is…
- The array [12, 7, 9, 14, 5, 11, 8, 10, 6] must be split into 3 contiguous parts so that the largest part sum is as small as possible. What…
- Coupons of 6 equally likely types are drawn with replacement. What is the expected number of draws until 4 different types have been seen?
- Counting sort (stable, processing the input from right to left with cumulative counts) is applied to a = [4, 2, 2, 8, 3, 3, 1, 4, 2]. At…
- LSD radix sort (decimal digits, stable counting sort on each digit, least significant first) is applied to [329, 457, 657, 839, 436, 720…
- A shell sort pass with gap 5 (a gapped insertion sort) is applied to [23, 12, 45, 3, 67, 8, 34, 19, 56, 2, 41, 28]. The cost of the pass…