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

Develop Pseudo-code (English-like) In the Find Largest pseudo-code algorithm of

ID: 3553775 • Letter: D

Question

Develop Pseudo-code (English-like)

In the Find Largest pseudo-code algorithm of Figure 2.14, listed below, if the numbers in

our list were not unique and therefore the largest number could occur more than once.

Modify the algorithm below to find all the occurrences of the largest number and

their position in the list


FIGURE 2.14


Get a value for n, the size of the list

Get values for A1, A2, . . . , An, the list to be searched

Set the value of largest so far to A1

Set the value of location to 1

Set the value of i to 2

While (i?n) do

If Ai > largest so far then

Set largest so far to Ai

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




Explanation / Answer

Get a value for n, the size of the list

Get values for A1, A2, . . . , An, the list to be searched

Set the value of largest so far to A1

Set the value of location to 1

Set the value of i to 2


While (i?n) do

If Ai >= largest so far then

Set largest so far to Ai

Add 1 to the value of i

End of the loop


Initialize j=1;

while(j<=n) do

if Aj==largest

location=j

Print out largest number location

add 1 to value of j

End of the loop


Stop

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote