subject

In this exercise, all integers are considered to be nonnegative, for simplicity. A divisor of an integer k is any integer d ≠ 0 such that k/d has no remainder. A common divisor for a set of integers is an integer that is a divisor for each integer in the set. Euclid’s algorithm for finding the greatest common divisor (GCD) of two nonnegative integers, m and n, can be written as follows:

1: procedure gcd(int m, int n)
2: if n = 0 then
3: answer ← m
4: else if m < n then
5: answer ← gcd(n, m)
6: else
7: r ← m - n ⋅ ⌊m/n⌋ //r is the remainder of mn
8: answer ← gcd(n, r)
9: end if
10: return ← anwser
11: end procedure

The preconditions for gcd(m, n) are that m ≥ 0, n ≥ 0 and m + n > 0.

Prove the following using induction:

a. If the preconditions of gcd(m, n) are satisfied, then the value that the function returns is some common divisor of m and n.
b. If the preconditions of gcd(m, n) are satisfied, then the value that the function returns is the greatest common divisor of m and n.

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 23:30, jcollings44
You picked the corridor which led you here. if the guards find you, they're going to be really angry! what is the synonym of angry
Answers: 1
image
Computers and Technology, 22.06.2019 13:30, baeethtsadia
Asoftware company hired ray, a college graduate to work in their development team. ray is assigned to work in the coding phase of a project. what happens during the coding phase of a software development project? a. the customer receives a working model of the software. b. developers convert the program design into code. c. developers gather requirements directly from the stakeholders. d. testing teams check the product for quality.
Answers: 1
image
Computers and Technology, 23.06.2019 08:00, hernandez09297
What is a scenario where records stored in a computer frequently need to be checked
Answers: 2
image
Computers and Technology, 23.06.2019 13:30, small77
Font size, font style, and are all aspects of character formatting.
Answers: 2
You know the right answer?
In this exercise, all integers are considered to be nonnegative, for simplicity. A divisor of an int...

Questions in other subjects:

Konu
Advanced Placement (AP), 30.12.2021 14:00