Question-58

Question-58

What of the following is an algorithm that locates the first occurrence of the largest element in a finite list of integers? The integers in the list are not necessarily distinct.

 

Solution

procedure first largest ( a1 , a2 , ……… , an : integers)

max = a1

location = 1

for  i = 2 to n

   if max < ai then

      max = ai

      location = i

return location

 

Leave a Reply