Professional Documents
Culture Documents
Correctness of Euclid'S Algorithm: N, and Clearly in Such A Case N Is The GCD of M and N. If R ! 0, Note That Any Number
Correctness of Euclid'S Algorithm: N, and Clearly in Such A Case N Is The GCD of M and N. If R ! 0, Note That Any Number
ALGORITHM
• After step E1, we have m = qn + r, for some integer q. If r = 0, then m is a multiple of
n, and clearly in such a case n is the GCD of m and n. If r !=0, note that any number
that divides both m and n must divide m – qn = r, and any number that divides both n
and r must divide qn + r = m; so the set of divisors of {m,n} is the same as the set of
divisors of {n,r}. In particular, the GCD of {m,n} is the same as the GCD of {n,r}.
Therefore, E3 does not change the answer to the original problem. [Knuth1]
algorithm
Algorithmic solution
Design and Analysis of Algorithms - Chapter 1 13
EXAMPLE OF
COMPUTATIONAL PROBLEM:
SORTING
• Statement of problem:
• Input: A sequence of n numbers <a1, a2, …, an>
• Algorithms:
• Selection sort
• Insertion sort
• Merge sort
• (many others)
Design and Analysis of Algorithms - Chapter 1 14
SELECTION SORT