题目
(a) (i) Describe how to carry out the first pass of a bubble sort when it is used to sort a list of numbers into ascending order.
(ii) Write down the circumstances under which a bubble sort stops.
A bubble sort, starting at the left-hand end of the list, is used to sort a list of ten numbers into ascending order. After a number of passes the list reads:
(b) Determine the maximum number of passes that could have taken place on this list. You must give a reason for your answer.
(c) Complete the bubble sort to produce a list of the numbers in ascending order. You only need to give the state of the list after each complete pass.
(d) Use the first-fit decreasing bin packing algorithm to determine how the ten numbers listed above can be packed into bins of size 4.
题目中文翻译
(a) (i) 描述当冒泡排序用于将 个数字的列表按升序排序时,如何执行第一次传递。
(ii) 写出冒泡排序停止的情况。
从列表左端开始的冒泡排序用于将十个数字的列表按升序排序。经过多次传递后,列表为:
(b) 确定此列表上可能已进行的最大传递次数。必须给出理由。
(c) 完成冒泡排序以产生升序的数字列表。只需给出每次完整传递结束后的列表状态。
(d) 使用首次适应递减装箱算法确定上面列出的十个数字如何装入大小为 4 的箱子中。