正在加载图片...
Built--Max-Heap正确性证明 At the start of each iteration of the for loop of lines 2-3,each node i+1, i+2.....n is the root of a max-heap. Initialization:Prior to the first iteration of the loop,i=n/2.Each node n/2+1,n/2+2.....n is a leaf and is thus the root of a trivial max-heap. Maintenance:To see that each iteration maintains the loop invariant,observe that the children of node i are numbered higher than i.By the loop invariant,there- fore,they are both roots of max-heaps.This is precisely the condition rered for the call MAX-HEAPIFY(A,i)to make node i a the MAX-HEAPIFY call preserves the property th 为什么算法是 are all roots of max-heaps.Decrementing i in th downto1,而不是 the loop invariant for the next iteration. upto length/2? Termination:At termination,i=0.By the loop invarian is the root of a max-heap.In particular,node 1 is.Built-Max-Heap正确性证明 为什么算法是 downto 1,而不是 upto length/2?
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有