Discrete Mathematics and Its Applications, Seventh Edition

Published by McGraw-Hill Education
ISBN 10: 0073383090
ISBN 13: 978-0-07338-309-5

Chapter 3 - Section 3.1 - Algorithms - Exercises - Page 202: 1

Answer

The maximum (which is returned) is $14.$ Check the solution for the series of steps.

Work Step by Step

The list is ${1, 8, 12, 9, 11, 2, 14, 5, 10, 4}.$ First, the algorithm sets max to be the first element which is $1$. It then begins looping over the list of numbers; It compares $1$ to $8$ and finds that $8$ is larger than one and hence assigns it to max. After that, it compares $12$ and $8$; seeing as $12$ is larger than $8$, it gets assigned to max. After this, $12$ gets compared to the next three numbers $9, 11, 2$ without any assignment or updates since all of them are less than $12$. The next number was $14$ which is greater than $12$ and gets assigned to max. Then, $14$ is greater than the remaining $3$ numbers $(5, 10, 4)$ and hence, no changes were done to max. Finally, the algorithm returns max which in this case is $14.$
This answer is currently locked

Someone from the community is currently working feverishly to complete this textbook answer. Don’t worry, it shouldn’t be long.