Invitation to Computer Science 8th Edition

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

Chapter 1 - Exercises - Page 39: 9

Answer

The first one( Fig 1.3$)$ is more efficient and elegant since it would look the same regardless of how many times the loop has to be performed. Only the value of WashCount would change.

Work Step by Step

The algorithm from Fig 1.3 contains an iterative operation (repeating a number of steps) and a value to keeping track of how many times the loop should be performed. The Fig 1.4 algorithm simply has steps which look exactly the same and take extra space while not providing enough new information. One would only have to read the 3 steps and count how many times the same steps are written which is what WashCount is for in the second algorithm. The first one is more efficient and elegant since it would look the same regardless of how many times the loop has to be performed. Only the value of WashCount would change.
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.