0% found this document useful (0 votes)
47 views2 pages

Heap Sort: Step-by-Step Guide

The document outlines the step-by-step process of Heap Sort using the array [5, 8, 3, 9, 2, 10, 1, 45, 32]. It details the construction of a Max Heap and the subsequent sorting process through a series of swaps and heapifications. The final sorted array is presented as [1, 2, 3, 5, 8, 9, 10, 32, 45].

Uploaded by

shani bharadwaj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views2 pages

Heap Sort: Step-by-Step Guide

The document outlines the step-by-step process of Heap Sort using the array [5, 8, 3, 9, 2, 10, 1, 45, 32]. It details the construction of a Max Heap and the subsequent sorting process through a series of swaps and heapifications. The final sorted array is presented as [1, 2, 3, 5, 8, 9, 10, 32, 45].

Uploaded by

shani bharadwaj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Heap Sort: Step-by-Step Process

Given Array: [5, 8, 3, 9, 2, 10, 1, 45, 32]

Step 1: Build Max Heap


Resulting Max Heap: [45, 8, 10, 5, 2, 3, 1, 9, 32]

Step 2: Sorting Process

Swap root with last element:


[32, 8, 10, 5, 2, 3, 1, 9, 45] - Heapify

Swap root with second last element:


[10, 8, 32, 5, 2, 3, 1, 9, 45] - Heapify

Swap root with third last element:


[9, 8, 1, 5, 2, 3, 32, 10, 45] - Heapify

Swap root with fourth last element:


[3, 8, 1, 5, 2, 9, 32, 10, 45] - Heapify

Swap root with fifth last element:


[2, 5, 1, 3, 8, 9, 32, 10, 45] - Heapify

Swap root with sixth last element:


[2, 3, 1, 5, 8, 9, 32, 10, 45] - Heapify

Swap root with seventh last element:


[1, 2, 3, 5, 8, 9, 32, 10, 45] - Heapify

Final swap:
[1, 2, 3, 5, 8, 9, 10, 32, 45] - Sorted Array
Final Sorted Array: [1, 2, 3, 5, 8, 9, 10, 32, 45]

You might also like