Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A three - heap with n elements can be stored in an array A s where A [ 0 ] contains the root of the

A three-heap with n elements can be stored in an array As where A[0] contains the
root of the tree.
a. Draw the three-heap that results from inserting 5,2,8,3,6,4,9,7,1 in that
order into an initially empty three-heap. You do not need to show the array
representation of the heap. You are only required to show the final tree,
although you draw intermediate trees.
b. Assuming that elements are placed in the array starting at location A[0],
give expressions to calculate the left, middle, and right children of the
element stored in A[i]:
Left child:
Middle child:
Right child:
c. Draw the array representation of your heap from part b.
Removing Arbitrary Items from Heaps: One way to remove any object from a binary
min heap is to decrease its priority value by 1 and then call deletemin. An alternative
is to remove it from the heap, thus creating a hole, and then repair the heap.
a. Write pseudocode for an algorithm that performs the remove operation using
the alternative approach described above. Your pseudocode should
implement the method named remove (int index), where index is the index
into the heap array for the object to be removed. Your pseudocode can call
the following methods: insert, deleteMin, percolateUp, and percolateDown.
You may assume that objects are just priority integers (no other data).
b. What is the worst-case complexity of the algorithm you wrote in part (a)?
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions