Discrete Mathematics and Its Applications, Seventh Edition

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

Chapter 5 - Section 5.4 - Recursive Algorithms - Exercises - Page 371: 19

Answer

--Algorithm 3 for computing gcd(a, b) when a and b are positive integers with a < b is correct.

Work Step by Step

--We use strong induction on a -. Basis step: If a = 0, -we know that gcd(0, b) = b for all b > 0, and that is precisely what the if clause does. --Inductive step: - Fix k > 0, assume -the inductive hypothesis—that the algorithm works correctly -for all values of its first argument less than k—and consider -what happens with input (k, b), wherek < b. Becausek > 0, -the else clause is executed, and the answer is whatever the -algorithm gives as output for inputs (b mod k, k). Because -b mod k < k, the input pair is valid. By our inductive hypothesis, -this output is in fact gcd(b mod k, k), which equals -gcd(k, b) by Lemma 1 in Section 4.3.
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.