Message215807
Hi,
I dont think its a bug.
The textbook definition of a min(or max) heap is
"Heaps are binary trees for which every parent node has a value less than or equal to any of its children."
Therefore,
when lista = [1,6,5,4], and heapify is run on it,it can be viewed as
1
/ \
4 5 6
or [1,4,5,6]
When listb=[1,6,5], running heapify on it,gives
1
/ \
6 5
or [1,6,5]
heapify maintains the heap-invariant - Every key is smaller than its children. This invariant is not violated in the above example.
The heappop maintains the heap-invariant after popping. The line in your code
[heapq.heappop(listb) for i in range(len(listb))]
is the heapsort algorithm!.
Hopefully, this clears your question. |
|
Date |
User |
Action |
Args |
2014-04-09 08:23:11 | Saimadhav.Heblikar | set | recipients:
+ Saimadhav.Heblikar, ezio.melotti, wchlm |
2014-04-09 08:23:11 | Saimadhav.Heblikar | set | messageid: <1397031791.6.0.938564664367.issue21185@psf.upfronthosting.co.za> |
2014-04-09 08:23:11 | Saimadhav.Heblikar | link | issue21185 messages |
2014-04-09 08:23:11 | Saimadhav.Heblikar | create | |
|