Proof that this assertion about heaps is true
smangano_at_ureach.com
Date: 10/18/04
- Previous message: Dave Seaman: "Re: Zenkin's paper on Cantor (reply of Dr. Zenkin)"
- Next in thread: Bill Wade: "Re: Proof that this assertion about heaps is true"
- Reply: Bill Wade: "Re: Proof that this assertion about heaps is true"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 18 Oct 2004 13:27:19 -0700
Hi all,
I am using a binary min heap in an effort to optimize a particular
piece of code whose details I believe are irrelevant to the question I
have. However, in a portion of this code I need to modify an arbitrary
element of the heap in such a way that I can guarantee the following
is true:
After modifying the heap, it is certain that the value of the element
modified is less than all other values in the heap. In other words,
this new element belongs at the front of the heap.
I will use C++ STL terminology, but what I am really after is if this
is true in general for heaps.
I know then that if iModIndex is the index of the item changed and vec
is the heap then:
make_heap(vec.begin(), vec.end(), greater<int>()); //greater<int>() is
a comparison functor needed to make this a min heap.
will definitly restore the heap by definition. However, given the
knowledge of the change made I belive it would be sufficient to say:
make_heap(vec.begin(), vec.begin() + iModIndex + 1, greater<int>()) ;
However, I also believe, and this is what I would like to prove, that
it is only necessary to say:
push_heap(vec.begin(), vec.begin() + iModIndex + 1, greater<int>()) ;
I apologize for using STL specific terminology. I really mean this to
be a general question about the properties of heaps and even if you
are not familiar with STL, I hope my intensions are fairly clear.
I have written a program that creates random heaps of sizes 4 thur
1000 and verified that this always works for every position in the
vector but obviously that is not a proof!
- Previous message: Dave Seaman: "Re: Zenkin's paper on Cantor (reply of Dr. Zenkin)"
- Next in thread: Bill Wade: "Re: Proof that this assertion about heaps is true"
- Reply: Bill Wade: "Re: Proof that this assertion about heaps is true"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|