Update heapify.py

This commit is contained in:
marina 2023-08-02 13:01:14 -07:00 committed by GitHub
parent e8882c2da0
commit f595c7b2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,13 @@
# -*- coding: utf-8 -*-
# author: bt3gl
# python's built-in heap differs from the standard implementation of a heap
# in two ways. firstly, it uses zero-based indexing, so it stores the root
# node at index zero instead of the size of the heap. secondly, the built-in
# module does not offer a direct way to create a max heap, instead, we must
# modify the values of each eelement when inserting in the heap, and when
# removing it from the heap.
import heapq
min_heap = [3,1,2]