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: 16

Answer

procedure smallest ($a_1, a_2, a_3,... a_n:$ a sequence of natural numbers) smallest $:=a_1$ for $i:=2$ to $n$ $\space\space\space$$\space\space\space$ if $a_i< $ smallest $\space\space\space$$\space\space\space$ smallest $:=a_i$ return smallest

Work Step by Step

The algorithm attempts to find the smallest value in a set of natural numbers. It is quite straightforward. We begin by intializing smallest to be the first index. We then loop over the other elements, always checking to see if we can find a smaller element or not. When we do, we update smallest. In the end we return smallest.
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.