From f595c7b2cfc8d791f8eb5a6b64bc3ff5d93012e5 Mon Sep 17 00:00:00 2001 From: marina <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Wed, 2 Aug 2023 13:01:14 -0700 Subject: [PATCH] Update heapify.py --- heaps/heapify.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/heaps/heapify.py b/heaps/heapify.py index 88a7838..bd4dfd2 100644 --- a/heaps/heapify.py +++ b/heaps/heapify.py @@ -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]