8-5 Average sorting
Suppose that, instead of sorting an array, we just require that the elements increase on average. More precisely, we call an
-element array k-sorted if, for all , the following holds: a. What does it mean for an array to be
-sorted? b. Give a permutation of the numbers
that is -sorted, but not sorted. c. Prove that an
-element array is -sorted if and only if for all . d. Give an algorithm that
-sorts an -element array in time. We can also show a lower bound on the time to produce a
-sorted array, when is a constant. e. Show that we can sort a
-sorted array of length in time. ( Use the solution to Exercise 6.5-9.) f. Show that when
is a constant, -sorting an -element array requires time. ( Use the solution to the previous part along with the lower bound on comparison sorts.)
a. Ordinary sorting
b.
c.
d. Shell-Sort, i.e., We split the
e. Using a heap, we can sort a
f. The lower bound of sorting each part is
本页面的全部内容在 小熊老师 - 莆田青少年编程俱乐部 0594codes.cn 协议之条款下提供,附加条款亦可能应用