Re: heap doesn't appear to work as described

2007-04-04 Thread 7stud
On Apr 4, 7:05 am, [EMAIL PROTECTED] wrote: > 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 kee

Re: heap doesn't appear to work as described

2007-04-04 Thread skip
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 unfortunat

Re: heap doesn't appear to work as described

2007-04-04 Thread skip
skip> Check the heapq docs for the constraints the Python heapq module skip> maintains: s/constraints/invariants/ Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: heap doesn't appear to work as described

2007-04-04 Thread 7stud
On Apr 3, 10:30 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > | > |>> My book says that in a heap, a value at position i will be smaller > |>> than the values at positions 2*i and 2*i + 1. > > I am sure your book either uses

Re: heap doesn't appear to work as described

2007-04-03 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | |>> My book says that in a heap, a value at position i will be smaller |>> 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

Re: heap doesn't appear to work as described

2007-04-03 Thread 7stud
On Apr 3, 5:27 pm, [EMAIL PROTECTED] wrote: > >> My book says that in a heap, a value at position i will be smaller > >> than the values at positions 2*i and 2*i + 1. > > Check the heapq docs for the constraints the Python heapq module maintains: > >http://docs.python.org/dev/lib/modu

Re: heap doesn't appear to work as described

2007-04-03 Thread skip
>> My book says that in a heap, a value at position i will be smaller >> than the values at positions 2*i and 2*i + 1. Check the heapq docs for the constraints the Python heapq module maintains: http://docs.python.org/dev/lib/module-heapq.html They are different than what you stat

heap doesn't appear to work as described

2007-04-03 Thread 7stud
My book says that in a heap, a value at position i will be smaller than the values at positions 2*i and 2*i + 1. To test that, I ran this program: -- from heapq import * from random import shuffle data = range(10) shuffle(data) heap = [] for n in data: heappush(heap, n) print heap