Next: Exercise 3.
Up: Quiz2
Previous: Exercise 1.
We consider the following algorithm, which computes the gcd of two integer numbers.
gcd(a : , b : ) : ==
1 if a = b then return a
2 if
a 0 mod2 and
b 0 mod2 then return
gcd(a/2, b/2)
3 if
a 0 mod2 and
b 1 mod2 then return
gcd(a/2, b)
3 if
a 1 mod2 and
b 0 mod2 then return
gcd(a, b/2)
4 if a > b then return
gcd((a - b)/2, b) else return
gcd((b - a)/2, a)
- Let na and nb the number of bits (in binary-expansion) of a and b
respectively.
Give an upper bound for the number of reursive calls needed to compute
gcd(a, b)?
- Give an upper bound for the number of machine word operations needed for
computing
gcd(a, b).
Answer 2
Answer 3
Next: Exercise 3.
Up: Quiz2
Previous: Exercise 1.
Marc Moreno Maza
2006-01-09