You are on page 1of 14

Euclidean GCD Analysis

Mohamed Ennahdi El Idrissi


m.ennahdielidrissi@aui.ma

Introduction
I got used to analyzing algorithms, and I wanted to
approve this skill by browsing different cases
I came to realize that methodology orbited around:
Regular, predictable algorithms;
A size or an element alike, symbolized as n.
I didnt know that attempting to analyze Euclidean GCD
algorithm would have me hit a wall:
Irregular algorithm behavior
No use n to consume, rather two elements x & y
My attempts were aiming to come up with the
appropriate recurrence relation
Introduction (contd)
I tried to gather as many academic references as I
could, discussing Euclidian GCD practical cases
A twist of luck: the work of Dr. Kiyoko F. Aoki-
Kinoshita Introduction to Algorithms, allowed
me to make a major breakthrough
I have been sampling (probing for the best test
values) on a C program I wrote myself
I could reach interesting cases for suitable GCD
analysis
Best testing values are Fibonacci pairs (F
n
, F
n-1
)


N.B. recursive and iterative versions of Euclidean GCD algorithm are alike
What is Euclidean GCD
Its a futility to
analyze, for
example, the case:
M = 500
And N = 2
GCD(M, N) = 1
We need to find a
situation like the
one depicted to the
right
E.g. M = 24, N = 15
5 iterations
Hint: Fibonacci pairs
do represent good
worst case scenarios
(M = 24, N = 15) causes
5 iterations/recursive
calls
Sampling
Dr. K.F.A.K. suggested a
decreasing factor of 3/2
Decreasing factor: 3/2
Fibonacci pairs: (55, 34)
The factor formula is: XY 2XY/3 = 3XY/3 2XY/3 = XY/3
Iteration X Y
Actual
Decrease
Expected
Decrease
Formula
XY/3
1 55 34 1870 - -
2 34 21 714 623 1870/3
3 21 13 273 238 714/3
4 13 8 104 91 273/3
5 8 5 40 34 103/3
6 5 3 15 13 40/3
7 3 2 6 5 15/3
8 2 1 2 3 6/2
We notice here expected decreases are less than or equal the actual decreases:
Appropriate upper bound?
Log
3
(x * y)


Sampling
Critique
(Non fibonacci case)



The actual number of iterations is 6
Fibonacci case


The actual number of iterations is 8 (upper bound
exceeded)

Critique
Fibonacci case (again)


The actual number of iterations is 24.
Lets attempt to find a better decreasing factor
Decreasing Factor
Actually, the decreasing factor is:


Euclidean GCD behaves like the following code
fragment
And such a fragment executes in:

We can prove this for recursive Euclidean GCD
(recursive relation)
for ( i = x * y ; i >= k ; i = i / d);
Let and





When

Therefore,
Conclusion
This is a mere attempt to deduce a more precise
order of growth for Euclidean GCD
Thanks to this analysis, we could infer that
Euclidean GCD is very fast algorithm, albeit worst
case
It was a good opportunity to find the recurrence
relation via two factors (fused in one):
Dividend
Divisor
For More Precision
Visit this link on math.stackexchange.com
The answer of the question is covering:
Best Case
Worst Case (Fibonacci)
Average Case

You might also like