Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#2. Analysis of d -ary heaps (11 pts) In class you did preliminary analysis of ternary heaps. Here we generalize to d -ary heaps: heaps

#2. Analysis of d-ary heaps (11 pts) In class you did preliminary analysis of ternary heaps. Here we generalize to d-ary heaps: heaps in which non-leaf nodes (except possibly the right-most one) have d children.

a. (3) How would you represent a d-ary heap in an array? Answer this question by:

Giving an expression for J-th-Child(i,j): the index of the j-th child as a function of the

index i of the given node, and the child index j within the given node.

Giving an expression for D-Ary-Parent(i): the index of the parent of a node as a

function of its index i within the array.

Checking that your solution works by showing that D-Ary-Parent(J-th-Child(i,j)) = i

(when you start at node i, and apply your formula to go to a child, and then your other formula to go back to the parent, you must end up back at i).

b. (2) What is the height of a d-ary heap of n elements as a function of n and d? By what factor does this height differ from that of a binary heap of n elements?

c. (3) Give an efficient implementation of Extract-Max in a d-ary max-heap. (Hint: How would you modify the existing code?) Analyze the running time of your implementation in terms of n and d. (Note that d must be part of your expression even if it occurs in a constant term.)

d. (3)GiveanefficientimplementationofInsertinad-arymax-heap.Analyzeitsrunning time in terms of n and d.

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

Find the derivative of the function. y = log 57x+1 dy dx

Answered: 1 week ago