While loop iterates through height of heap and is thus O(lgn)
Insert(A, key) 1 HeapSize(A) = HeapSize(A) + 1 2 i = HeapSize(A) 3 while i > 1 and A[Parent(i)] < key 4 A[i] = A[Parent(i)] 5 i = Parent(i) 6 A[i] = key
Priority Queue Example