Docsity

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

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];

}