Question

(Data Structure) Suppose we want to store the data of a binary heap in an array....

(Data Structure)

Suppose we want to store the data of a binary heap in an array. Show the data of that array after inserting the given keys one by one. Assume that initially binary heap is empty. Show all steps of insertions.

Note: No need to show the changes for each step of “percolate up”. The contents of the array must be shown after completing one insertion.

Create the “Min Heap” for the following data set

7,      3,      18,    -9,     1,      50,    15,    4,      27,    0

Homework Answers

Answer #1

Features of Heap data structure:

1) The left child of a node can be accessed by the formula, 2*i+1, "i" is the position of the parent, in the array
2) The right child of a node can be accessed by the formula, 2*i+2, "i" is the position of the parent, in the array
3) Minheap is a data structure where the parent is the smallest when compared to both their children.

To insert a node in binary min heap, put the element at the last position, recursively call for its parent and check if it's the smallest.

Steps of insertion:

1) Increase the heap size by 1.
2) Insert the new element at the end of the heap.
3)Heapify using a bottom up approach.

Following the steps, the heap obtained after constructing a binary min heap will be:

Note that the output produced is the resultant array and the min heap in C++ is represented by priority_queue.

Know the answer?
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
Similar Questions
The Heapsort algorithm is based on the heap data structure. The algorithm works by: repeatedly removing...
The Heapsort algorithm is based on the heap data structure. The algorithm works by: repeatedly removing the maximum value, i.e. the element at position 0, from the heap; and then restoring the heap property, until the heap is empty. Given the array [73, 57, 0, 47, 8, 9], first turn it into a Max-Heap, and then into a sorted array in ascending order, using the Heapsort algorithm. You have to show the array content of the heap, as well as...
# data structure Recall that the Insertion sort algorithm (for sorting an array A) from low...
# data structure Recall that the Insertion sort algorithm (for sorting an array A) from low to high has the skeleton form: for (i = 1; i < A.length; i++) { details omitted } For i = 1 to 6, show how the contents of the array is rearranged if at all) after each iteration of the for-loop. (10 pts) the original array A                                            A 6. 4. 7. 5....
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the...
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the code to be written with these) I need Class river, Class CTRiver and Class Driver with comments so I can learn and better understand the code I also need a UML Diagram HELP Please! Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong()...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs in Chapter 1 of your textbook are not complete. They are used for illustration purpose only. The implementation of Listing 1-1 on page 39 is explained in Chapter 2. And, in order to see the result of using it, we will need the following set of files: i. BagInteface.java – the specification only. ii. ArrayBag.java – the implementation of BagInerface.java. iii. ArrayBagDemo.java – a...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
GoodClothes and MIS: Case from struggle to revamp Headquartered in Dubai, GoodClothes is a highly successful...
GoodClothes and MIS: Case from struggle to revamp Headquartered in Dubai, GoodClothes is a highly successful department retailer offering completely designed casual clothing and accessories. The company operates 10 stores in all seven emirates and 1 store in Al Ain. The company owns 6 stores and franchises 5. For some time, marketing managers targeted population between the ages 40 and 60 who like loose, comfortable clothes. Then, management was tempted to stock its stores with clothes for a younger population...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT