Invitation to Computer Science 8th Edition

Published by Cengage Learning
ISBN 10: 1337561916
ISBN 13: 978-1-33756-191-4

Chapter 2 - Exercises - Page 87: 15

Answer

The condition "while $(i \leq n)$" indicates that every single element of the list is going to be compared to the value of the largest so far. The comparison occurs here: $I f A_{i}>$ largest so far. It will be true only if the element analyzed is larger than the largest so far, in which case its value will be assigned to the largest so far. This means that even if we encounter the same value as the number already stored as the largest so far it won't take it into account since it would be equal to it, not larger. The conclusion is that even if the largest number occurs more than once, we will already have stored it after its the first occurrence.

Work Step by Step

--
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.