Skip to content

Commit 455ae94

Browse files
committed
Wording
1 parent f6a7a8b commit 455ae94

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/algebra/extended-euclid-algorithm.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ This implementation of extended Euclidean algorithm produces correct results for
7272
## Iterative version
7373
7474
It's also possible to write the Extended Euclidean algorithm in an iterative way.
75-
Because we it avoids recursion, the code will run a little bit faster than the recursive one.
75+
Because it avoids recursion, the code will run a little bit faster than the recursive one.
7676
7777
```cpp extended_gcd_iter
78-
int gcd(int a, int b, int &x, int &y) {
78+
int gcd(int a, int b, int& x, int& y) {
7979
x = 1, y = 0;
8080
int x1 = 0, y1 = 1, a1 = a, b1 = b;
8181
while (b1) {
@@ -88,9 +88,9 @@ int gcd(int a, int b, int &x, int &y) {
8888
}
8989
```
9090

91-
If you look at the variable `a1` and `b1`, they taking exactly the same values as in the iterative version of the normal [Euclidean algorithm](algebra/euclid-algorithm.html).
91+
If you look closely at the variable `a1` and `b1`, you can notice that they taking exactly the same values as in the iterative version of the normal [Euclidean algorithm](algebra/euclid-algorithm.html). So the algorithm will at least compute the correct GCD.
9292

93-
To see why the algorithm work, you can check that the following invariants will at all time (before the while loop, and at the end of each iteration): $x \cdot a + y \cdot b = a_1$ and $x_1 \cdot a + y_1 \cdot b = b_1$.
93+
To see why the algorithm also computes the correct coefficients, you can check that the following invariants will hold at any time (before the while loop, and at the end of each iteration): $x \cdot a + y \cdot b = a_1$ and $x_1 \cdot a + y_1 \cdot b = b_1$.
9494
It's trivial to see, that these two equations are satisfied at the beginning.
9595
And you can check that the update in the loop iteration will still keep those equalities valid.
9696

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy