Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

25. The greatest common divisor of two positive integer x and y, denoted ged(x,y), is the largest integer d such that both x/d and y/d

image text in transcribed

25. The greatest common divisor of two positive integer x and y, denoted ged(x,y), is the largest integer d such that both x/d and y/d are integers. Euclid's Elements, written around 300BCE, describes the following recursive algorithm to compute ged(x,y): Euclid's algorithm is sometimes incorrectly described as the oldest recursive algorithm, or even the oldest notrivial algorithm, even though the Egyptian duplation and mediation algorithmswhich is both notrivial and recursive-predates Euclid by at least 1500 years ON EucLIGCEEA if x=y return else if x >y return EuctIDGCDX - yy) else return EucLInGCDEX,y-x) (a) Prove that EUCLIDGCD correctly computes ged(x,y).** Specifically i. Prove that EUCLIDGCD(x,y) divides both x and y. ii. Prove that every divisor of x and y is a divisor of EUCLIDGCD(x,y). (b) What is the worst-case running time of BUCLIDGCD(x, y), as a function of x and y? (Assume that computing x - y requires O(logx +logy) time.) (c) Prove that the following algorithm also computes ged(x,y): PASTEUCLIDGCLEAR: if y=0 return x else if x > retum PASTEUCLIDGCD(y,x mody) else retum Pastucu GCDx, y modx) (d) What is the worst-case running time of FASTEUCLIDGCD(x,y), as a function of x and y? (Assume that computing x mod y takes O(logx logy) time.) (e) Prove that the following algorithm also computes god(x,y): BINARY if x=y retum else if x and y are both even return 2. BINARYGCDEX/2,y/2) else if x is even retum BINARYGCD(x/2,y) else if y is even return BINARYGCD(x,y/2) else if x > return BINARYGCD((x - y)/2,y) else return BENARYGCDEX.(y-x)/2) "Euclid did not do this. Proposition in Elements Book VII states that af EUCLIDGCD(x,y)-1, nx and y are relatively prime (that is, ged(x,y) - 1), but the proof only considers the special ex mod fy mod x mody)) - 1. Proposition states that if x and y are not relatively prime, EUCLIDGCD(x,y) - gedex,y), but the proof only considers the special cases ged(x,y) y ged(x,y) y mod x mody). Finally, these two Propositions do not make a complete proof EUCLIDGCD is correct. Don't be like Euclid. EX ( What is the worst-case running time of BINARYGCD(x, y), as a function of x and y? (Assume that computing x - y takes O(log x +logy) time, and computing = /2 requires O(logz) time.) 25. The greatest common divisor of two positive integer x and y, denoted ged(x,y), is the largest integer d such that both x/d and y/d are integers. Euclid's Elements, written around 300BCE, describes the following recursive algorithm to compute ged(x,y): Euclid's algorithm is sometimes incorrectly described as the oldest recursive algorithm, or even the oldest notrivial algorithm, even though the Egyptian duplation and mediation algorithmswhich is both notrivial and recursive-predates Euclid by at least 1500 years ON EucLIGCEEA if x=y return else if x >y return EuctIDGCDX - yy) else return EucLInGCDEX,y-x) (a) Prove that EUCLIDGCD correctly computes ged(x,y).** Specifically i. Prove that EUCLIDGCD(x,y) divides both x and y. ii. Prove that every divisor of x and y is a divisor of EUCLIDGCD(x,y). (b) What is the worst-case running time of BUCLIDGCD(x, y), as a function of x and y? (Assume that computing x - y requires O(logx +logy) time.) (c) Prove that the following algorithm also computes ged(x,y): PASTEUCLIDGCLEAR: if y=0 return x else if x > retum PASTEUCLIDGCD(y,x mody) else retum Pastucu GCDx, y modx) (d) What is the worst-case running time of FASTEUCLIDGCD(x,y), as a function of x and y? (Assume that computing x mod y takes O(logx logy) time.) (e) Prove that the following algorithm also computes god(x,y): BINARY if x=y retum else if x and y are both even return 2. BINARYGCDEX/2,y/2) else if x is even retum BINARYGCD(x/2,y) else if y is even return BINARYGCD(x,y/2) else if x > return BINARYGCD((x - y)/2,y) else return BENARYGCDEX.(y-x)/2) "Euclid did not do this. Proposition in Elements Book VII states that af EUCLIDGCD(x,y)-1, nx and y are relatively prime (that is, ged(x,y) - 1), but the proof only considers the special ex mod fy mod x mody)) - 1. Proposition states that if x and y are not relatively prime, EUCLIDGCD(x,y) - gedex,y), but the proof only considers the special cases ged(x,y) y ged(x,y) y mod x mody). Finally, these two Propositions do not make a complete proof EUCLIDGCD is correct. Don't be like Euclid. EX ( What is the worst-case running time of BINARYGCD(x, y), as a function of x and y? (Assume that computing x - y takes O(log x +logy) time, and computing = /2 requires O(logz) time.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

Question How is life insurance used in a DBO plan?

Answered: 1 week ago