D cross heap

Source: Internet
Author: User

6-2 Analysis of the D-cross heap
The D-cross heap is similar to the binary heap, but (one possible exception) each of the non-leaf nodes has d children instead of 2.
A) how to represent a D-cross heap in an array?

B) What is the height of the Cross stack containing n elements?

C) give an effective implementation of the EXTRACT-MAX of the maximum heap of D, and express its running time with D and N.

D) give an effective implementation of insert for the D-cross heap, and use d and N to indicate its running time.

E) An effective implementation of increase-Key (A, I, K) is provided. In this process, a [I] <-- max (A [I], k) is first executed ), and accordingly update the structure of the Max heap of the D-cross. Use D and N to indicate its running time.

 

Analysis and answer:

Similar to binary heap, it can be represented by arrays.

A)In the array, it indicates the D cross heap. Given the subscript I of each node, its parent node parent (I) AND ITS K-son can be calculated simply:

Parent (I) = partition I/D Partition ⌉

Child (I, K) = D * I + k, 0 ≦ k <D

 

B)The number of knots in a full d cross heap with H is d ^ h-1. Assume that if the height of the D-cross heap of n elements is H

D ^ (h-1) %n %d ^ H-1

Therefore, we can obtain the d = Your logd (n) token )⌉

 

C)You can first swap the elements at the end of the heap and the elements at the top of the heap, and then adjust the elements at the top of the heap using the MAX-HEAPIFY method, the whole process is as follows:

HEAP-EXTRACT-MAX) <br/> If heap-size [a] <1 <br/> then error "heap underflow" <br/> MAX versions A [1] <br/> A [1] using a [heap-size [a] <br/> heap-size [a] Using Heap-size [a]-1 <br/> MAX-HEAPIFY (, 1) <br/> return Max

The MAX-HEAPIFY is a recursive process with iterations less than the heap height logd (n ). In each iteration, we need to compare it with all the son nodes, so the number of comparisons is D. The total running time is dlogd (n)

 

D)You can first insert-∞ to the end of the heap, and then call increase-key to increase the value of this element to the current value. The process is as follows:

MAX-HEAP-ISNERT (A, key) <br/> heap-size exceed heap-size + 1 <br/> A [heap-size] between-∞ <br/> increase-Key (, heap-size [a], key)

As you can see from the following, it is the same as the running time of the increase-key process, it is also logd (N)

 

 E)The implementation that can be iterated only needs to be compared with the parent node each time, and then gradually adjusted up. The whole process is as follows:

Increase-Key (A, I, K) <br/> A [I] maximum max (A [I], K) <br/> while I> 1 and a [I]> A [Parent (I)] <br/> do exchange a [I] a [Parent (I)] <br/> I have parent (I) </P> <p>

Because the maximum number of upward adjustments in the while loop is the heap height and only needs to be compared with the parent node each time, the total running time is logd (N)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.