CLRS:max_heap and min_heap operation (pseudocode)

时间:2022-10-28 20:12:21

//max_heap

heap_maximum:return A[1]    O(1);

Extract_Heap_maximum:swap(A[1],A[heap.size])    adjust up to down from A[1] to hold the max_heap character   O(lgn)   every stepfind max child

increase_Heap_max(i,key):[key>=A[i]],adjust down to up from A[i] toA[1] until satsify the max_heap        O(lgn) every step find father

insert_heap_max:heap_size ++;A[heap.size]=key; increase_heap_max(heap.size,key)       O(lgn)    find father

 

//min_heap

heap_minimum:return A[1]    O(1);

Extract_Heap_miniimum:swap ,adjust find min child;    O(lgn)

decrease_heap_min:change value ,adjust up find smaller father    O(lgn)