Posts

Showing posts from 2023

SELECT with groups of 3

Image
Exercise 9.3-1 asks you to show that the SELECT algorithm still runs in linear time if the elements are divided into groups of 7. This problem asks about dividing into groups of 3. Show that SELECT runs in linear time if you divide the elements into groups whose size is any odd constant greater than 3. Show that SELECT runs in O(nlgn) time if you divide the elements into groups of size 3 Because the bound in part (b) is just an upper bound, we do not know whether the groups-of-3 strategy actually runs in O(n) time. But by repeating the groups-of-3 idea on the middle groups of medians, we can pick a pivot that guarantees O(n) time. The SELECT3 algorithm on the next page determines the ith smallest of an input array of n>1 distinct elements. Describe in English how the SELECT3 algorithm works.Include in your description one or more suitable diagrams. Show that SELECT3 runs in O(n) time in the worst case. [1]   The worst-case linear-time median-f...

kth quantiles of an n-element set

Image
Problem statement Exercise 9.3-8 The kth quantiles of an n-element set are the k - 1 order statistics that divide the sorted set into k equal sized sets (to within 1). Give an O(nlgk)-time algorithm to list the kth quantiles of a set. [1] Definitions In statistics and probability, quantiles are cut points dividing the range of a probability distribution into continuous intervals with equal probabilities, or dividing the observations in a sample in the same way. There is one fewer quantile than the number of groups created. [2] Approach Let's write a divide and conquer algorithm using selection to solve this problem. What if we find the l=nk2k th smallest number  and partition the array around it. Then, we can find the first k2 cut points in the first half l and the remaining k2 cut points in the second half nl. At each step, we keep on dividing $...