Language: EN FI

Exercises > MinHeap Insert

These exercises demonstrate the content of the ByTheMark service. These are meant for private individuals for learning data structures and algorithms. If you want to try out more content, you can register to the ByTheMark Personal free of charge.

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

  Last modified Tue Mar 01 20:54:04 EET 2011