【问题标题】:heap sort may be considered as insertion sort or selection sort done on a heap data structure instead of a list? Which one will it be?堆排序可以被认为是在堆数据结构而不是列表上完成的插入排序或选择排序?会是哪一个?
【发布时间】:2025-12-20 23:25:10
【问题描述】:

可以考虑堆排序 作为

A. Insertion sort done on a heap data structure instead of a list.
B. Selection sort done on a heap data structure instead of a list.
C. Bubble sort done on a heap data structure instead of a list.
D. None of the above.

【问题讨论】:

  • 你认为答案是什么?我们不是来帮你做作业的。

标签: data-structures selection insertion heapsort


【解决方案1】:

答案应该是B

正如在堆排序期间执行最小或最大heapify 时,我们分别从整个堆中检索最小或最大元素并将其放置在堆的root 上。

选择排序做同样的事情。从数组中找到最小/最大元素并将其放置在 arr[0] 中。然后再次从数组的其余部分中找到最小/最大元素并将其放置在 arr[1] 等处。

【讨论】: