Question

Define the term Heap. Illustrate the tree changes in the bottom-up Make Heap algorithm applied to construct a max-Heap for th

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Heap is a binary tree based data structure. It is an array object that can be viewed as a nearly complete binary tree. Each node of the tree corresponds to an element of the array that stores the value in the node. The heap tree is completely filled on all levels except possibly the lowest. Lowest level possibly filled from left up to a point.

Heap tree is categorized into max-heap and min-heap.

Max-heap: Every nodes of a max-heap except root node has the "less than or equal to" ( \leq ) relation with its parent node.

Min-heap: Every nodes of a min-heap except root node has the "greater than or equal to" ( \geq ) relation with its parent node.

A heap can be stored as an array. Here we need to build a max-heap tree for a given array [1,2,3,4,5,6,7]. The algorithm MakeHeap(A) we are using here contains a subroutine that is Max-Heapify(A,i).

Assume that given array is A and its elements stored in the location 1 through 7.

1 2 3 4 5 6 7

We can use MakeHeap(A) and Max-Heapify(A,i) to build a max-heap of the array A.

Length of array = length(A) = 7

Procedure for MakeHeap(A) and Max-Heapify(A,i) are given in the attachment. Illustration of the changes in the array and tree also mentioned in attachment.

aus el IF node curo - Procedure We can repousent biscury korea array. the parent localed at ith location of correy, then its

the -Now We illustrabing changes array by using the maketteap() algorith of tree and rithm to constouct a max-beap au: Step 1

In fig (c) we can see the final array and max-heap of given elements.

Note: MakeHeap() algorithm using a bottom-up approach to heapify the given array. In thi sexample the length of the array is 7. MakeHeap() procedure calls the Max-Heapify() for each value of i. ie, 3,2 and 1.

I hope I have answered your query.

Add a comment
Know the answer?
Add Answer to:
Define the term Heap. Illustrate the tree changes in the bottom-up Make Heap algorithm applied to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT