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

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 02:30
Which option completes the explanation for conflict of interest in an organization
Answers: 1
question
Computers and Technology, 24.06.2019 16:00
Which of the following characters is acceptable to use in a filename? ? / – %
Answers: 1
question
Computers and Technology, 24.06.2019 21:30
Write an algorithm to check if a number is even or odd and show with flow chart step by step
Answers: 2
question
Computers and Technology, 25.06.2019 01:00
When a new name is registered on the internet, the process can take two hours to four hours four hours to three days two hours to two days one hour to eight hours
Answers: 1
You know the right answer?
In this exercise, all integers are considered to be nonnegative, for simplicity. A divisor of an int...
Questions
question
Chemistry, 12.12.2020 16:40
question
Mathematics, 12.12.2020 16:40
question
Mathematics, 12.12.2020 16:40
question
English, 12.12.2020 16:40
question
Geography, 12.12.2020 16:40
Questions on the website: 13722363