Question

Apply Euclid’s algorithm to find the GCD (Greatest Common Divisor) of 126 and 28. Describe or...

Apply Euclid’s algorithm to find the GCD (Greatest Common Divisor) of 126 and 28.

Describe or give the pseudocode of the consecutive integer checking algorithm for finding the GCD. What is the time complexity of this second algorithm? Explain.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Euclid Algoithm:

int gcd(int m, int n)

{

    if (m % n == 0)

        return n;

    return gcd(n, m % n);

}

m = 126

n = 28

gcd( 126, 28 )

Here, ( 126 % 28 = 14 ) != 0.

So, again recursively call gcd( 28 , 126 % 28 ) = gcd( 28, 14 )

gcd( 28, 14 )

Here, ( 28 % 14 = 0 ) == 0.

So, it returns 14.

Hence, gcd = 14.

pseudocode of the consecutive integer checking algorithm:

Let a, b be the two numbers

  1. Set T with the smaller value among {a,b}. So, T = min(a, b)
  2. Find the value of m % T. If the output is not 0, then we move to 4, otherwise we move to 3.
  3. Find the value of n % T. If the output is not 0, then we move to 4, otherwise we get the ans as t and the algorithm is terminated.
  4. The value of T is decremented by 1.

T = T - 1

Add a comment
Know the answer?
Add Answer to:
Apply Euclid’s algorithm to find the GCD (Greatest Common Divisor) of 126 and 28. Describe or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN PYTHON Write a recursive function for Euclid's algorithm to find the greatest common divisor (gcd)...

    IN PYTHON Write a recursive function for Euclid's algorithm to find the greatest common divisor (gcd) of two positive integers. gcd is the largest integer that divides evenly into both of them. For example, the gcd(102, 68) = 34. You may recall learning about the greatest common divisor when you learned to reduce fractions. For example, we can simplify 68/102 to 2/3 by dividing both numerator and denominator by 34, their gcd. Finding the gcd of huge numbers is an...

  • a Find the greatest common divisor (gcd) of 322 and 196 by using the Euclidean Algorithm....

    a Find the greatest common divisor (gcd) of 322 and 196 by using the Euclidean Algorithm. gcd- By working back in the Euclidean Algorithm, express the gcd in the form 322m196n where m and n are integers b) c) Decide which of the following equations have integer solutions. (i) 322z +196y 42 ii) 322z +196y-57

  • 1) Use the Euclidean algorithm (write in pseudocode) to find the greatest common divisor of 8...

    1) Use the Euclidean algorithm (write in pseudocode) to find the greatest common divisor of 8 898 and 14 321. 2) Program the Euclidean algorithm in 1) by using C++ programming language. 3) What is the greatest common divisor of 8 898 and 14 321? 4) Next, extend the Euclidean algorithm (write in pseudocode) to express gcd(8 898; 14 321) as a linear combination of 8 898 and 14 321. 5) Continue the programming in 2) to program the Extended...

  • 1. (10 points) GCD Algorithm The greatest common divisor of two integers a and b where...

    1. (10 points) GCD Algorithm The greatest common divisor of two integers a and b where a 2 b is equal to the greatest common divisor of b and (a mod b). Write a program that implements this algorithm to find the GCD of two integers. Assume that both integers are positive. Follow this algorithm: 1. Call the two integers large and small. 2. If small is equal to 0: stop: large is the GCD. 3. Else, divide large by...

  • Implement in Scheme Euclid’s algorithm computing the greatest common divisor of two integers as a tail...

    Implement in Scheme Euclid’s algorithm computing the greatest common divisor of two integers as a tail recursive function. What is the class of arithmetic functions that can be written in tail recursive way? Hint: Generalize out of examples you are familiar with.

  • Cryptography Computer Security Greatest Common Divisor Assignment Instructions In software, implement the Euclidean algorithm to find...

    Cryptography Computer Security Greatest Common Divisor Assignment Instructions In software, implement the Euclidean algorithm to find the greatest common divisor of any two positive integers. It should implement the pseudocode provided in the text. It should allow the user to enter two integers.   Your program should output the intermediate values of q, r1, r2 for each step and should return the greatest common divisor. Challenge component: Allow the user's input to be zero as well as the positive integers. Provide...

  • I want the code in C++ The greatest common divisor (GCD) of two integers is the...

    I want the code in C++ The greatest common divisor (GCD) of two integers is the largest integer that evenly divides each of the numbers. Write a function called GCD that has a void return type, and accepts 3 parameters (first two by value, third by reference). The function should find the greatest common divisor of the first two numbers, and have the result as its OUTGOING value. Write a main function that asks the users for two integers, and...

  • Consider the problem of finding the Greatest Common Divisor (GCD) of two positive integers a and...

    Consider the problem of finding the Greatest Common Divisor (GCD) of two positive integers a and b. It can be mathematically proved that if b<=a GCD(a, b) = b, if (a mod b) = 0; GCD(a, b) = GCD(b, a mod b), if (a mod b) != 0. Write a recursive function called GCD with signature “public static int GCD(int a, int b)” that returns the greatest common divisor of two positive integers a and b with b <= a....

  • Euclid’s Elements (300 BC) shows that the greatest common divisor of two integers does not change...

    Euclid’s Elements (300 BC) shows that the greatest common divisor of two integers does not change if the smaller is subtracted from the larger. Write a program (in MIPS assembly) that implements this algorithm to find the GCD of two integers. Follow this algorithm: 1. Call the two integers a and b. 2. If a and b are equal: stop: a is the GCD. 3. Subtract the smaller from the larger. Replace the larger with the result 4. Repeat steps...

  • We discuss the Euclidean algorithm that finds the greatest common divisor of 2 numbers u and...

    We discuss the Euclidean algorithm that finds the greatest common divisor of 2 numbers u and v. We want to extend and compute the gcd of n integers gcd⁡(u1,u2,….un). One way to do it is to assume all numbers are non-negative, so if only one of if uj≠0 it is the gcd. Otherwise replace uk by uk mod uj  for all k≠j where uj is the minimum of the non-zero elements (u’s). The algorithm can be made significantly faster if one...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT