heap doesn't appear to work as described
skip at pobox.com
skip at pobox.com
Wed Apr 4 09:05:01 EDT 2007
>>>> My book says that in a heap, a value at position i will be than the
>>>> values at positions 2*i and 2*i + 1.
>> I am sure your book either uses 1-based arrays or a 0-based arrays
>> with the first not used. The need to keep these alternatives in mind
>> is an unfortunate fact of programming life.
> My book uses lists.
Yes, but is the first element of the list addressed as element 1 or element
0? Terry was doing the transformation from 1-based to 0-based indexing to
demonstrate that the invariants you described were the same as those
maintained by Python's heapq module.
Skip
More information about the Python-list
mailing list