3. This problem is to analyze the worst-case number of key comparisons for a simple 2-level sorting algorithm described below. Let n = p2 be the number of elements to be sorted.
2.0 Divide the elements into p sets, each of size p.
2.1 Sort the elements within each set using insertion sort.
2.2 Let M[i] be the largest element in the sorted set i. Find the maximum value of all
M[i], 1 ≤ i ≤ p. Output this MAX element, while deleting it from its set.
2.3 Repeat step 2.2 in a similar fashion for ﬁnding the second MAX, third MAX, etc.
(a) What is the worst-case number of key comparisons to sort each set of p elements in step 2.1?
(b) Give a reasonable upper bound for the worst-case number of key comparisons to ﬁnd the MAX
in each iteration of step 2.2.
Hint: You can ﬁnd a reasonable upper bound by observing that each subsequent iteration takes
no more than the ﬁrst iteration.
(c) Use (a) and (b) to ﬁnd a reasonable upper bound for the worst-case number of key comparisons
(in terms of n) for the entire algorithm.