Question-80

Question-80

Give a recursive  algorithm for finding the maximum of a finite set of integers , making use of the fact that the maximum of n integers is the larger of the last integer in the list and the maximum of the first n – 1 integers in the list.

 

Solution

procedure max (a1 , a2, ……..an : integers)

if n = 1 then return a

else

m = max (a1 , a2,…..)

an – 1

if m > an

then return m

else return an

 

Leave a Reply

Your email address will not be published. Required fields are marked *