Heap as array: ascendItem: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 28: | Line 28: | ||
# <math>\ell := Positions[ID]</math> | # <math>\ell := Positions[ID]</math> | ||
'''Proof:''' Obvious: | '''Proof:''' Obvious: | ||
==Induction step== | ==Induction step== |
Revision as of 11:10, 30 September 2014
Algorithmic problem: Heap as array: ascendItem
Prerequisites:
Type of algorithm: loop
Auxiliary data:
- A natural number [math]\displaystyle{ \ell }[/math] denoting a position within the heap.
- A pointer [math]\displaystyle{ h }[/math] of type heap item.
- A natural number [math]\displaystyle{ p }[/math] denoting a position within the heap.
Abstract view
Invariant: After [math]\displaystyle{ i }[/math] iterations:
- [math]\displaystyle{ 1\le \ell \le n }[/math].
- The left and right child's key and their children's keys of the current heap item [math]\displaystyle{ h }[/math] identified by [math]\displaystyle{ \ell }[/math] are bigger than the key [math]\displaystyle{ h.key }[/math].
Variant:
- [math]\displaystyle{ \ell }[/math] decreases each step and points to a valid position within the heap that is at a higher level than before.
Break condition:
- [math]\displaystyle{ \ell = 1 }[/math] or [math]\displaystyle{ TheHeap[\lfloor \ell /2 \rfloor ].key \le TheHeap[\ell].key }[/math]
Induction basis
Abstract view:
- Set [math]\displaystyle{ \ell }[/math] to the positions of the heap item to be ascended.
Implementation:
- [math]\displaystyle{ \ell := Positions[ID] }[/math]
Proof: Obvious: