Heap as array: ascendItem
Revision as of 11:08, 30 September 2014 by Cuozzo (talk | contribs) (Created page with "Category:Algorithm Category:Method of an implementation of a data structure '''Algorithmic problem:''' Heap as array: ascendItem '''Prerequisites:''...")
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: