Skip to content
CalcGospel 國際數學圖譜
返回

IAL 2023 Jan D1 Q3

A Level / Edexcel / D1

IAL 2023 Jan Paper · Question 3

题目

Problem

1.81.42.61.62.80.93.10.81.22.40.61.8 \quad 1.4 \quad 2.6 \quad 1.6 \quad 2.8 \quad 0.9 \quad 3.1 \quad 0.8 \quad 1.2 \quad 2.4 \quad 0.6

(a) Use the first-fit bin packing algorithm to determine how the numbers listed above can be packed into bins of size 5.

(3)

The list is to be sorted into descending order.

(b) (i) Perform one pass of a bubble sort, starting at the left-hand end of the list. You must write down the list that results at the end of the first pass.

(ii) Write down the number of comparisons and the number of swaps performed during the first pass.

(3)

After a second pass using this bubble sort, the updated list is

2.61.82.81.63.11.41.22.40.90.80.62.6 \quad 1.8 \quad 2.8 \quad 1.6 \quad 3.1 \quad 1.4 \quad 1.2 \quad 2.4 \quad 0.9 \quad 0.8 \quad 0.6

(c) Use a quick sort on this updated list to obtain the fully sorted list in descending order. You must make your pivots clear.

(4)

(d) Apply the first-fit decreasing bin packing algorithm to the fully sorted list to pack the numbers into bins of size 5.

(3)
题目中文翻译

1.81.42.61.62.80.93.10.81.22.40.61.8 \quad 1.4 \quad 2.6 \quad 1.6 \quad 2.8 \quad 0.9 \quad 3.1 \quad 0.8 \quad 1.2 \quad 2.4 \quad 0.6

(a) 使用首次适应装箱算法确定上面列出的数字如何装入大小为 5 的箱子中。

列表要按降序排序。

(b) (i) 从列表左端开始执行一次冒泡排序传递。必须写出第一次传递结束时的结果列表。

(ii) 写出第一次传递期间执行的比较次数和交换次数。

使用此冒泡排序进行第二次传递后,更新的列表为

2.61.82.81.63.11.41.22.40.90.80.62.6 \quad 1.8 \quad 2.8 \quad 1.6 \quad 3.1 \quad 1.4 \quad 1.2 \quad 2.4 \quad 0.9 \quad 0.8 \quad 0.6

(c) 对此更新的列表使用快速排序获得降序完全排序的列表。必须清楚标出枢轴。

(d) 对完全排序的列表应用首次适应递减装箱算法,将数字装入大小为 5 的箱子中。

解答

(a)

解法一

思路

展开

按题目给出的原始顺序逐个处理数字。每个数字都从 Bin 1 开始检查,放入第一个剩余容量足够的箱子;只有现有箱子都放不下时才开新箱。

答题过程

展开

Applying first-fit bin packing gives

BinContentsTotal
11.8, 1.4, 1.64.8
22.6, 0.9, 0.8, 0.64.9
32.8, 1.24.0
43.13.1
52.42.4

(b)(i)

解法一

思路

展开

要按降序排列,从左端开始比较每一对相邻数字;若左数小于右数就交换。完成一次从左至右的传递后,当前最小值 0.6 会被推到最右端。

答题过程

展开

After one complete pass, the list is

1.8, 2.6, 1.6, 2.8, 1.4, 3.1, 0.9, 1.2, 2.4, 0.8, 0.6.\boxed{ 1.8,\ 2.6,\ 1.6,\ 2.8,\ 1.4,\ 3.1, \ 0.9,\ 1.2,\ 2.4,\ 0.8,\ 0.6}.

(b)(ii)

解法一

思路

展开

十一个数字的一次完整冒泡传递会比较十对相邻数字。逐次追踪 (b)(i) 的交换,可数得其中六次需要交换。

答题过程

展开

The first pass uses

10 comparisons and 6 swaps.\boxed{10\text{ comparisons and }6\text{ swaps}}.

(c)

解法一

思路

展开

采用 middle-right 规则:每个尚未排好的子列表都选择中间两个元素中靠右的一个作为枢轴。每轮把大于枢轴的数放在左侧、小于枢轴的数放在右侧,并对各子列表继续使用同一规则。即使第四轮后列表已排序,仍要写出第五轮。

答题过程

展开

Using middle-right pivots gives:

StagePivot(s)Resulting list
11.42.6, 1.8, 2.8, 1.6, 3.1, 2.4, 1.4, 1.2, 0.9, 0.8, 0.6
21.6, 0.82.6, 1.8, 2.8, 3.1, 2.4, 1.6, 1.4, 1.2, 0.9, 0.8, 0.6
32.8, 0.9, and singleton 0.63.1, 2.8, 2.6, 1.8, 2.4, 1.6, 1.4, 1.2, 0.9, 0.8, 0.6
4Singleton 3.1, 1.8, and singleton 1.23.1, 2.8, 2.6, 2.4, 1.8, 1.6, 1.4, 1.2, 0.9, 0.8, 0.6
52.43.1, 2.8, 2.6, 2.4, 1.8, 1.6, 1.4, 1.2, 0.9, 0.8, 0.6

Hence the fully sorted list is

3.1, 2.8, 2.6, 2.4, 1.8, 1.6, 1.4, 1.2, 0.9, 0.8, 0.6.\boxed{3.1,\ 2.8,\ 2.6,\ 2.4,\ 1.8,\ 1.6, \ 1.4,\ 1.2,\ 0.9,\ 0.8,\ 0.6}.

解法二

思路

展开

也可采用官方接受的 middle-left 规则,即每个偶数长度子列表选择中间靠左的元素作为枢轴。必须在所有子列表中一致使用这一规则,并把最后一次无变化的传递写出。

答题过程

展开

Using middle-left pivots gives:

StagePivot(s)Resulting list
11.42.6, 1.8, 2.8, 1.6, 3.1, 2.4, 1.4, 1.2, 0.9, 0.8, 0.6
22.8, 0.93.1, 2.8, 2.6, 1.8, 1.6, 2.4, 1.4, 1.2, 0.9, 0.8, 0.6
3Singleton 3.1, 1.8, singleton 1.2, and 0.83.1, 2.8, 2.6, 2.4, 1.8, 1.6, 1.4, 1.2, 0.9, 0.8, 0.6
42.6, singleton 1.6, and singleton 0.63.1, 2.8, 2.6, 2.4, 1.8, 1.6, 1.4, 1.2, 0.9, 0.8, 0.6

Therefore the same fully sorted list is obtained:

3.1, 2.8, 2.6, 2.4, 1.8, 1.6, 1.4, 1.2, 0.9, 0.8, 0.6.\boxed{3.1,\ 2.8,\ 2.6,\ 2.4,\ 1.8,\ 1.6, \ 1.4,\ 1.2,\ 0.9,\ 0.8,\ 0.6}.

(d)

解法一

思路

展开

按 (c) 的递减顺序逐个放入数字,并对每个数字从 Bin 1 开始寻找第一个可容纳它的箱子。这与 (a) 的 first-fit 规则相同,差别只在于先按递减顺序排序。

答题过程

展开

Applying first-fit decreasing gives

BinContentsTotal
13.1, 1.84.9
22.8, 1.6, 0.65.0
32.6, 2.45.0
41.4, 1.2, 0.9, 0.84.3