Binary Heap Algorithm: Finding the Maximum Element, Assignments of Design and Analysis of Algorithms

The solution to an assignment question about implementing a binary heap algorithm to find the maximum element in an array. the array and its corresponding index for parts (a) and (b) of the question, as well as the pseudocode for the algorithm in part (c).

Typology: Assignments

2019/2020

Uploaded on 09/11/2020

muhammad-arslan-22
muhammad-arslan-22 🇵🇰

1 document

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assignment
pf3
pf4
pf5

Partial preview of the text

Download Binary Heap Algorithm: Finding the Maximum Element and more Assignments Design and Analysis of Algorithms in PDF only on Docsity!

Assignment

Question No. 1

(a)

(c)

(d) Part a

Part b

Part c

(e)

Yes binary heap in part (a) is the same as the binary heap in part (b).

Question No. 2

(a)

If left arr ==

return;

set max = arr[0]

set max_index=0;

for i>n

if arr[i]> max

set max_index=

set max =arr[i]

print max_index;

(b)

find_max_index(arr[],size,index,max_index)

if (index == size)

return max_index;

if(arr[index]>arr[max_index]

max_index=index;

return find_max_index(arr[],size,index+1,max_index)

(c)

find_max(arr,int l,int r)

if(left arr ==1)

{

return A[1];

}