Bartleby Related Questions Icon
Related questions
Question
The algorithm of Euclid computes the greatest common divisor (GCD) of two integer numbers a and b. The following pseudo-code is the original version of this algorithm.
Algorithm 1 Euclid1(a,b)
Require: a, b > 0
Ensure: a = GCD(a, b)
while a ̸= b do
if a > b then
a ← a − b
else
b ← b − a
end if
end while
return a
We want to prove the correctness of this algorithm using the loop invariant technique. Answer the following questions:
a. Show the property is maintained during the execuation of the While loop (i.e., maintenance property).
b. Prove the termination property and conclude.
c. What would happen if a > 0 and b = 0 and thus the pre-condition is not satisfied?
Expert Solution
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
Step by stepSolved in 4 steps
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, data-structures-and-algorithms and related others by exploring similar questions and additional content below.Similar questions
- grade 12 computer science chapter Recursion * Returns true if there exists a subset of the items in* weights[start..weights.length] that sum to goal.* pre: items in weights[start..weights.length] > 0* post: true has been returned if there exists a subset* of items in weights[start..weights.length] that sum to goal.arrow_forwardGiven the following recursively defined set S: Basis: 0 € S and 7 € S Recursive rule: if x ES and y = S, then: • x+yЄS x-yes Prove that every element in S is divisible by 7.arrow_forward%matplotlib inline import numpy as np from matplotlib import pyplot as plt import matharrow_forward