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, 21.06.2019 22:00
Draw the hierarchy chart and design the logic for a program that calculates service charges for hazel's housecleaning service. the program contains housekeeping, detail loop, and end-of-job modules. the main program declares any needed global variables and constants and calls the other modules. the housekeeping module displays a prompt for and accepts a customer's last name. while the user does not enter for the name, the detail loop accepts the number of bathrooms and the number of other rooms to be cleaned. the service charge is computed as $40 plus $15 for each bathroom and $10 for each of the other rooms. the detail loop also displays the service charge and then prompts the user for the next customer's name. the end-of-job module, which executes after the user enters the sentinel value for the name, displays a message that indicates the program is complete.
Answers: 2
question
Computers and Technology, 22.06.2019 08:00
What best describes a career pathway in a lodging career? a worker starts out as an amusement attendant, then becomes a recreation worker, and then becomes a gaming worker within five years. a worker starts out as a bell hop, then becomes a night clerk, and then becomes a hotel manager within five years. a worker starting out as a tour guide, then becomes a travel clerk, and then becomes a travel agent within five years. a worker starts out as a server, then becomes a food preparer, and then becomes a head chef within five years.
Answers: 1
question
Computers and Technology, 22.06.2019 22:10
Asequential circuit contains a register of four flip-flops. initially a binary number n (0000 ≤ n ≤ 1100) is stored in the flip-flops. after a single clock pulse is applied to the circuit, the register should contain n + 0011. in other words, the function of the sequential circuit is to add 3 to the contents of a 4-bit register. design and implement this circuit using j-k flip-flops.
Answers: 1
question
Computers and Technology, 23.06.2019 09:30
Name the range function that would generate the following list of integers values: 0,1,2,3,4,5.
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
Mathematics, 30.10.2019 04:31
question
Mathematics, 30.10.2019 04:31
question
Mathematics, 30.10.2019 04:31
Questions on the website: 13722361