I am trying an assignment on Heaps i.e. how to extract elements and bubble them down:
% binary min-heap container
% let us assume the heap contains the following elements already and
% is in a consistent state
BinMinHeap = [];BinMinHeap(1).pos = [3,3]; BinMinHeap(1).key = 1;BinMinHeap(2).pos = [4,2]; BinMinHeap(2).key = 3;BinMinHeap(3).pos = [3,2]; BinMinHeap(3).key = 2;BinMinHeap(4).pos = [3,1]; BinMinHeap(4).key = 4;BinMinHeap(5).pos = [4,3]; BinMinHeap(5).key = 5;% extract the minimal element from the heap and store it in "ExtractedElement"
ExtractedElement = ...;%make heap consistent again by first moving the bottom element
%to the top and then down the binary tree
consistent = false;while ~consistent ...; end
Best Answer