Related questions
The
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.
a. In a first attempt to prove the correctness of this algorithm, we propose the following loop invariant property: "GCD(a, b) is a factor of a and b". Explain why this property will
not help you as is.
b. Use your previous observation to propose another loop invariant property that will
help you to prove the correctness of the version of Euclid’s algorithm presented above.
c. Show that your loop invariant property is true before executing the While loop for
the first time (i.e., initialization property)
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps
- 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
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education