题目
(i) A list of twelve numbers is to be sorted into ascending order.
(a) Use a quick sort to obtain the sorted list. You should show the result of each pass and identify your pivots clearly.
(b) Show how the binary search algorithm is used to try to locate the number 40 in the list. You must clearly indicate your choice of pivots and which part of the list you are rejecting.
(ii) A different list of nine distinct integers is to be sorted into descending order.
The list is sorted using bubble sort. The first three passes are
| Pass 1 | 23 | 20 | 32 | x | 15 | 19 | 8 | 22 | 6 |
|---|---|---|---|---|---|---|---|---|---|
| Pass 2 | 23 | 32 | 20 | x | 19 | 15 | 22 | 8 | 6 |
| Pass 3 | 32 | 23 | 20 | 19 | x | 22 | 15 | 8 | 6 |
Determine the range of possible values of .
题目中文翻译
(i) 一个包含十二个数字的列表需要按升序排列。
(a) 使用快速排序获得排序后的列表。应显示每一轮的结果并清楚标明基准元素。
(b) 展示二分搜索算法如何尝试在列表中定位数字 40。必须清楚说明基准元素的选择以及被排除的列表部分。
(ii) 另一个包含九个不同整数的列表需要按降序排列。
使用冒泡排序对该列表进行排序。前三轮如下:
| 第1轮 | 23 | 20 | 32 | x | 15 | 19 | 8 | 22 | 6 |
|---|---|---|---|---|---|---|---|---|---|
| 第2轮 | 23 | 32 | 20 | x | 19 | 15 | 22 | 8 | 6 |
| 第3轮 | 32 | 23 | 20 | 19 | x | 22 | 15 | 8 | 6 |
确定 的可能值范围。