Heap Sort Implementation in Python

Here I share my Python implementation of heap sort algorithm. Heap sort is O(n log n) sorting algorithm though quicksort is used more frequently. You should learn heap sort to implement priority queue or at least learn the internals of priority queue. 🙂

In the Python code, I directly followed the heap sort algorithm presented in Introduction to Algorithms by CLRS.

# heapsort

def max_heapify(li, i, heap_size):
l = i * 2 #left(i)
r = l + 1 #right(i)
if l li[i]:
largest = l

Read the entire article at the source link… Tamim Shahriar

#codango #developer #development #coder #coding

We're happy to share this resource that we found. The content displayed on this page is property of it's original author and/or their organization.


Leave a Reply

Your email address will not be published. Required fields are marked *