Chapter 32: Heap Sort

前言

Heap sort的作法就是將資料集建成max或min heap再利用comparison-based來進行sort。

大綱

  • Getting started

  • Example

  • Implementation

  • Performance

Example

  • 先把array的資料轉成max heap

  • 每次都把最大元素搬到array的最後一個index,再把被交換的元素搬到正確位置。

    • You simply repeat the swapping and sifting steps until you reach a heap of size 1. The array is then fully sorted.

Implementation

Last updated