Vanshikapandey30 / Hacktoberfest2024

It's time to contribute to HacktoberFest 2024 :)
https://hacktoberfest.com
28 stars 63 forks source link

HeapSort.java, #Hacktoberfest2024 #69

Closed jatinn-sw closed 7 hours ago

jatinn-sw commented 7 hours ago

The Heap Sort first builds a max heap from the input array using the heapify method, ensuring that each parent node is greater than its child nodes. Once the heap is constructed, the algorithm repeatedly extracts the maximum element (the root of the heap) and swaps it with the last element in the heap. After reducing the heap size, it calls heapify again to maintain the heap property. Additionally, utility functions like heapify maintain the max heap structure, while swap exchanges two elements in the array. The main method tests the sorting on a sample array, displaying both the original and sorted arrays, resulting in an efficient O(n log n) sorting process.