Question: 3. Assume we have this problem: Given a value n >= 2 and a list containing exactly n unique numbers called A,,A,, A find and

3. Assume we have this problem: "Given a value n >= 2 and a list containing exactly n unique numbers called A,,A,, A find and print out both the largest value in the list and the position in the list where that largest value occurred". The following is a sample algorithm to solve it: (figure 2.14 form your textbook). FIGURE 2.14 Get a value for n the size of the list Get values for A, A..., A, the list to be searched Set the value of largest so far to A Set the value of location to 1 Set the value of ito 2 While (is n) do If A > largest so far then Set largest so far to A Set location to i Add 1 to the value of i End of the loop Print out the values of largest so far and location Stop Algorithm to find the largest value in a list If the numbers in the list were not unique, would the algorithm report the first or the last occurrence of the largest number if it occurred several times? Explain your answer. (For example assume the list of numbers is: 2,5,6,20,2,5,7,8,10,20,9,10, you can see the largest number is 20 and it appears twice)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
