''' Luis Andrés López Mañán Program written by hand as a draft on 09/19/2022 Credit goes to GeeksForGeeks Link: https://www.geeksforgeeks.org/python-program-for-heap-sort/ Last access on 09/19/2022 Program wrriten and edited on 10/10/2022 ''' # Python program for implementation of heap Sort (Part I) # This function heapifies a subtree rooted at an index # i. Also, n is the size of a heap and arr is array. def heapify(lista, n, i): # largest is root for now largest = i # left child of root left = 2 * i + 1 # right child of root right = 2 * i + 2 # Checks if root has a left child and is greater # than root if l < n and lista[i] < lista[l] : largest = l # Checks if root has a right child and is greater # than root if r < n and lista[largest] < lista[r]: largest = r # If necessary, this changes root by swapping va- # lues lista[i], lista[largest] = lista[largest], lista[i] heapify(lista, n, largest)