Language: EN FI

Exercises > Heap operations

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.

Search the k'th smallest element by the following algorithm. First, insert the given keys (Stream of Keys) one by one into the Heap below. Second, delete k=3 times the smallest element from the heaps. After each operation, make sure that the heap-order property: "the parent is smaller than its child" is preserved.

Algorithm 1 Select(Stream of keys, k)

for each key in Stream of keys do
Heap-Insert(A, key)
end for
for i ← 1 to k do
r = Heap-Extract-Min(A)
end for
return r

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