L4 (Modular Exponentiation and GCD) Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

The modular exponentiation problem is trying to compute the value of x ^ y mod N.

What is the most efficient algorithm for this?
What is the runtime of this algorithm?

A

Uses properties of modular arithmetic. It branches and recurses on if y is even or odd. Base case is y = 0.

func modexp(x, y, N):
if y == 0: return 1
z = modexp(x, floor(y/2), N)
if y is even: return z^2 mod N
if y is odd: return x*z^2 mod N

runtime is O(n^3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the GCD (greatest common divisor) of two numbers?

A

The GCD (Greatest common divisor) of two numbers is the largest integer that divides both of them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is euclid’s rule for GCD of two numbers?

A

If a and b are positive integers with a >= b, then

gcd(a, b) = gcd(b, a mod b)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write an algorithm to compute the GCD of two numbers a, and b using euclid’s rule.

A

func euclid_gcd(a, b):
if b == 0: return a
return euclid_gcd(b, a mod b)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly