Heap as array: ascendItem: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Category:Algorithm Category:Method of an implementation of a data structure '''Algorithmic problem:''' Heap as array: ascendItem '''Prerequisites:''...") |
mNo edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | |||
[[Category:Algorithm]] | [[Category:Algorithm]] | ||
[[Category:Method of an implementation of a data structure]] | [[Category:Method of an implementation of a data structure]] |
Revision as of 11:08, 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: