Exercise 1
How would our original algorithm change if we computed the divisors of by examining the numbers from to in reverse order, from down to ?
Not cross-checked
This solution has not been cross-checked against the answer printed in NCERT.
Only the scan direction changes, so the divisors are found largest first.1. Start with an empty list-of-divisors.
2. For each \(\displaystyle j\) in \(\displaystyle n, n-1, \ldots, 1\): if \(\displaystyle j\) divides \(\displaystyle n\), add \(\displaystyle j\) at the end.\[n=18:\ [\,] \to [18] \to [18,9] \to [18,9,6] \to [18,9,6,3] \to [18,9,6,3,2] \to [18,9,6,3,2,1] \]The gcd algorithm then builds common-divisors in decreasing order too, so Step $\displaystyle 5$ must report the leftmost element, not the rightmost.\[\text{common-divisors}(375,825) = [75,25,15,5,3,1] \;\Rightarrow\; \gcd(375,825)=75 \]Answer: The same divisors are found, but in decreasing order; in the gcd algorithm Step $\displaystyle 5$ reports the leftmost element instead of the rightmost.