MinHeap Insert

Hide text Hide pseudo-code
Insert the stream of keys into an originally empty binary heap. The heap is depicted in binary tree representation even though the implementation is an array starting from index 1 (the root node).
Algorithm MinHeap-Insert(A, key)

heap-size[A] ← heap-size[A] + 1
while i > 1 and A[Parent(i)] > key
do      A[i] ← A[Parent(i)]
A[i] ← key

  Created Fri Oct 30 13:52:50 EET 2009 - Powered by SVG-hut