Wednesday, June 18, 2008

Heap-Increase-key

Heap-Increase-key (H, i, k)

The above Procedure increases value of the element i's key with the new value ‘k’, which is assumed to be atleast as large as element i's current value.
Step 1 Is Smaller ?
If (k < H [i]) then
message :“new key ’k’ is smaller than current key”
return
else
goto step 2
Step 2 Adusting the new key ‘k’
set H [i]  k
loop
while (i > 1 and H [Parent (i) ] < H [i] )
set H [i]  H [Parent (i) ]
set i  Parent (i)
end loop
Step 3 return at the point of call
return

No comments: