Introduction to Algorithms
Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
Question
Book Icon
Chapter 31, Problem 1P

(a)

Program Plan Intro

To prove that if both a and b are even, then gcd(a,b)=2×gcd(a2,b2)

(a)

Expert Solution
Check Mark

Explanation of Solution

If a and b are both even, then it can be written that = 2(a2) and b = 2(b2) , such that all the factors stated are integers. Therefore by using BATCHPOLLARDRHO(n,B) ,which states that common factor 2 from both factors can be taken out of the whole function, it can be proved that gcd(a,b)=2×gcd(a2,b2) .

(b)

Program Plan Intro

To prove that if a is odd and b is even, then gcd(a,b)=gcd(a,b2)

(b)

Expert Solution
Check Mark

Explanation of Solution

If b is even and a is odd, then it can be written = 2(b2) , where (b2) is an integer. As, it is known that a is not divisible by 2 (a is odd), the extra factor of 2 which is in b can’t be part of gcd of the given both numbers. It states that gcd(a, b) = gcd(a,b2) . Now imagine = gcd(a, b) . As d is the common divisor, a must be divisible by d , therefore, d shouldn’t contain even factors. Which states that d also divides a and b2 . This states that gcd(a,b)gcd(a,b2) . This inequality holds true even for the reverse procedure. As, the inequalities hold both ways, it results in equality gcd(a,b)=gcd(a,b2) .

(c)

Program Plan Intro

To prove that if both a and b are odd, then gcd(a,b)=gcd(ab2,b)

(c)

Expert Solution
Check Mark

Explanation of Solution

if both a and b are odd, therefore a - b, where a > b is also an odd number. Therefore, gcd(a, b) = gcd( b, b) . Let

  d = gcd(a, b) d'= gcd( b, b) .

Then, there exists n1, n2 such that n1a+n2= d . It can be rewritten as n1(ab)+(n1+n2)b=d . Therefore, dd' . To compute reverse, let n'1a+n'2= d' so that n'1(ab)+n'2b=d' . It can be rewritten as n'1a+(n'2n'1)b=d' , therefore d'd . This means that gcd(a, b) = gcd( b, b) = gcd(b, a  b) . This inequality holds true even for the reverse procedure. As, the inequalities hold both ways, it results in equality. Therefore, gcd(a,b)=gcd(ab2,b) .

(d)

Program Plan Intro

To design an efficient binary gcd algorithm for integers a and b where ab and runs in O(lga) time.

(d)

Expert Solution
Check Mark

Explanation of Solution

  BINARYGCD(a,b)

if a mod 2  1 then

if b mod 2  1 then

return BINARYGCD((  b)2, b)

else return BINARYGCD(a, b2)

end if

else

  if b mod 2  1 then

return BINARYGCD(a2, b)

else

return ×BINARYGCD(a2, b2)

end if

end if

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Fermat's "Little" Theorem states that whenever n is prime and a is an integer, a^n−1≡1modn Then 281825≡ 263 mod827. c) If a=146 and n=331, then efficiently compute 146332≡ mod331Use The Extended Euclidean Algorithm to compute281^1≡362 mod827. Then 281^825≡???mod827. c) If a=146 and n=331, then efficiently compute146^332≡ ???mod331
Implement the Euclidean algorithm to find the greatest common denominator a) give an example of how to obtain the greatest common denominator of (12345, 54321).
Describe the Euclidean algorithm and its use in finding the greatest common divisor (GCD) of two integers. Provide a step-by-step example.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education