Computer Science Homework Solutions
Problem
#137258

Algorithms

Trace the action of the algorithm NaiveGCD for the following input pairs.

a. (24,108)

b. (23,108)

c. (89,144)

d. (1953,1937)

Exercise 1.8:
Repeat Exercise 1.7 for the algorithm EuclidGCD.

Attached file(s):
Attachments
function NaiveGCD.doc  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

function NaiveGCD.doc
function NaiveGCD(a, b)

Input: a, b (two positive integers)

Output: gcd(a, b) (the greatest common divisor of a and b)

while a ≠ b do

if a > b then

a ( a – b

else

b ( b – a

endif

endwhile

return(a)

end NaïveGCD

function EuclidGCD(a, b)

Input: a, b (two nonnegative integers)

Output: gcd(a, b) (the greatest common divisor of a and b)

while b ≠ 0 do

Remainder ( a mod b

a ( b

b ( Remainder

endwhile

|

~

¤

¦

А

В

2

X

ђ

¬

Ш

т

urn(a)

end EuclidGCD

function BabylonianSQRT(a, error)

Input: a (a positive number), error (a positive real number)

accurate to within error

x ( a

while |x - a/x| > error do

x ( (x + a/x)/2

endwhile

return(x)

end BabylonianSQRT
Solution
What is this?
By OTA - Overall OTA Rating
Debraj Banerjee, MIT (IP) - 4.8/5
Purchase Cost Now
$2.19 CAD (was ~$15.96)
Included in Download
  • Plain text response
  • Attached file(s):
    • Naive+Euclid.xls
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
Browse