Heap : Inserting an element into a heap using BubbleUp
Lets consider the min heap here.
Inserting the key k in the given heap. Consider the heap:
Insert k at the end of the last level
a) If the heap property is not broken you are done. Suppose k = 10. Here 10 is more than 4, hence min-heap property i.e. parent < child is already followed. Hence everything ok.
b)If the heap property is broken, then you have to bubble up the added child until heap property is restored.
[Read More]