Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given an array A[1..7]=17,23,12,32,24,15,9, run Build-Max-Heap (A,7) to convert A into a max-heap. BUILD-MAX-HEAP (A,n) 1 for i=n/2 downto 1 2 MAX-HEAPIFY (A,i,n) MAX-HEAPIFY (A,i,n)

image text in transcribed

Given an array A[1..7]=17,23,12,32,24,15,9, run Build-Max-Heap (A,7) to convert A into a max-heap. BUILD-MAX-HEAP (A,n) 1 for i=n/2 downto 1 2 MAX-HEAPIFY (A,i,n) MAX-HEAPIFY (A,i,n) l= LEFT (i) r=RIGHT(i) if ln and A[l]>A[i] largest =l else largest =i if rn and A[r]>A[ largest ] largest =r if largest =i exchange A[i] with A[ largest ] MaX-HEAPIFY (A, largest,n) (1) What will be the resultant array A after running Build-Max-Heap (A,7) on the given array A. Please write your answer as a sequence of numbers separated by ", ". For example: 1,2,3,4,5,6,7 (2) How many key comparisons were made by Build-Max-Heap (A,7) in total? Given an array A[1..7]=17,23,12,32,24,15,9, run Build-Max-Heap (A,7) to convert A into a max-heap. BUILD-MAX-HEAP (A,n) 1 for i=n/2 downto 1 2 MAX-HEAPIFY (A,i,n) MAX-HEAPIFY (A,i,n) l= LEFT (i) r=RIGHT(i) if ln and A[l]>A[i] largest =l else largest =i if rn and A[r]>A[ largest ] largest =r if largest =i exchange A[i] with A[ largest ] MaX-HEAPIFY (A, largest,n) (1) What will be the resultant array A after running Build-Max-Heap (A,7) on the given array A. Please write your answer as a sequence of numbers separated by ", ". For example: 1,2,3,4,5,6,7 (2) How many key comparisons were made by Build-Max-Heap (A,7) in total

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

1. How do most insects respire ?

Answered: 1 week ago

Question

Who is known as the father of the indian constitution?

Answered: 1 week ago

Question

1.explain evaporation ?

Answered: 1 week ago

Question

Who was the first woman prime minister of india?

Answered: 1 week ago

Question

Explain the concept of going concern value in detail.

Answered: 1 week ago