50.4k views
1 vote
Consider the following version of the Euclidean algorithm to compute gcd(a,b):

Step 1: Swap the numbers if necessary to have a ≤ b;
Step 2: If a = 0, then return b;
Step 3: If a ≠ 0, then replace b by b-a and go to step (1).

Carry out this algorithm to compute gcd(19,2)

User Webaware
by
7.5k points

1 Answer

2 votes

Final answer:

The gcd(19,2) is 0.

Step-by-step explanation:

Step 1: Swap the numbers if necessary to have a ≤ b. In this case, 19 ≤ 2, so no swapping is needed.



Step 2: If a = 0, then return b. Since a = 19 ≠ 0, we move to the next step.



Step 3: Replace b by b-a and go to step (1). Using the values for a and b, we have 2 - 19 = -17.



Step 1: Swap the numbers if necessary to have a ≤ b. In this case, we need to swap the values of a and b because 2 ≤ -17 is not true.



Step 2: If a = 0, then return b. Since a = 2 ≠ 0, we move to the next step.



Step 3: Replace b by b-a and go to step (1). Using the new values for a and b, we have -17 - 2 = -19.



Step 1: Swap the numbers if necessary to have a ≤ b. In this case, we need to swap the values of a and b because 2 ≤ -19 is not true.



Step 2: If a = 0, then return b. Since a = -17 ≠ 0, we move to the next step.



Step 3: Replace b by b-a and go to step (1). Using the new values for a and b, we have -19 - (-17) = -2.



Step 1: Swap the numbers if necessary to have a ≤ b. In this case, 2 ≤ -2 is not true, so we need to swap the values of a and b.



Step 2: If a = 0, then return b. Since a = -2 ≠ 0, we move to the next step.



Step 3: Replace b by b-a and go to step (1). Using the new values for a and b, we have -2 - 2 = -4.



Step 1: Swap the numbers if necessary to have a ≤ b. In this case, -2 ≤ -4 is true, so no swapping is needed.



Step 2: If a = 0, then return b. Since a = -4 ≠ 0, we move to the next step.



Step 3: Replace b by b-a and go to step (1). Using the new values for a and b, we have -4 - (-2) = -2.



Step 1: Swap the numbers if necessary to have a ≤ b. In this case, -2 ≤ -2 is true, so no swapping is needed.



Step 2: If a = 0, then return b. Since a = -2 ≠ 0, we move to the next step.



Step 3: Replace b by b-a and go to step (1). Using the new values for a and b, we have -2 - (-2) = 0.



Step 2: If a = 0, then return b. Since a = 0, we can return the value of b, which is 0.

User Ziyaddin Sadygly
by
7.8k points