首页 > 编程知识 正文

CLRSmaxheap and minheap operation pseudocode

时间:2023-05-04 05:31:45 阅读:235370 作者:4517

//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)

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。