Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. In class we developed a procedure or algorithm to find the largest of three n

ID: 3717053 • Letter: 1

Question

1. In class we developed a procedure or algorithm to find the largest of three numbers. Suppose we want to pick the largest of four numbers instead of three. We can of course, use the same logic and develop the algorithm. It is clearly evident that the algorithm for four numbers is going to be bigger (with more steps.), but not too long If we, however, try to find the largest of five numbers using the same strategy (there is nothing wrong in doing that) the algorithm will become to large (a bit confusing). For instance, if we want to find the largest of a set of numbers assuming that we do not know how many numbers are there in the set. Our logic is no good. Thus, it fails the test of generality. An alternative logic is needed to solve this problem. Develop an algorithm to pick the largest of set of numbe rs

Explanation / Answer

The algorithm to find the largest number from a set:

Input: L // a set of n numbers

Output: Largest_num // the largest number in the list

Largest_num = L[0] // Let the first number in the list L be the largest number initially

While(!End of the list)

m = get next number in the list L;

If (m> Largest_num) // comparison done with all the numbers in the list

Largest_num = m;

Else

continue;

endIf

end While

return(Largest_num)