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 370: 15

Answer

--Recursive algorithm for computing the greatest common divisor of two non negative integers a and b with a < b using the fact that gcd(a, b) = gcd(a, b − a).

Work Step by Step

--procedure gcd(a, b: nonnegative integers) -{a < b assumed to hold} -if a = 0 then return b -else if a = b − a then return a -else if a < b − a then return gcd(a, b − a) -else return gcd(b − a, a)
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.