def heap_sort(ary): n = len(ary) first = int(n / 2 - 1) for start in range(first, -1, -1): # 3~0 revese max_heapify(ary, start, n - 1) # from start for end in range(n - 1, 0, -1): ary[end], ary[0] = ary[0], ary[end] max_heapify(ary, 0, end - 1) retur…