Originally Posted by

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

procedure largest(a1,a2,.....,an: integer)

if n==1

then largest (a1,a2,.....,an: integer) : = a1

else largest(a1,a2,.....,an: integer) : = max(largest(a1,a2,.....,an-1),an)

is the answer correct or not ?? if not please suggest the correct answer. appreciate your reply.

Thanks

I think your pseudo-code use is not acceptable, something more like:

Code:

procedure largest(n:unsigned, a[1:n]: integer)
if n=1
then
return a[1]
else
return max(largest(n-1, a[1:n-1]),a[n])

would be better.

Alternativly can you give a link to a site that specified the syntax for your pseudo-code.

CB