b.
The recursive divide-and-conquer algorithm for gcd is given
as
procedure gcd(a,b)
Input: Two n-bit integers a,b
Output: GCD of a and b
if a = b:
return a
else if (a is even ∧ b is even):
return 2 * gcd( a/2,b/2)
else if (a is odd ∧ b is even):
return gcd(a, b/2)
else if (a is even ∧ b is odd):
return gcd(a/2, b)
else if (a is odd ∧ b is odd ∧ a > b):
return gcd( (a−b)/2,b)
else if (a is odd ∧ b is odd ∧ a < b):
return gcd(a,(b−a)/2)
c and d.
Assume that a and b are n-bit numbers. Size of a and b is 2n bits. Out of 4 if conditions, every one except the case when a is odd and b is even, decreases the size of a and b to 2n − 2 bits whereas that case decreases it to 2n − 1 bits. Each of the operations is constant time operation as we are dividing or multiplying the numbers by 2. For two cases subtraction of two n-bit numbers are involved which is c·n where n is the number of bits of the operand. Therefore in the worst case:
T(2n) = T(2n − 1) + cn
T(2n − 1) = T(2n − 2) + cn
T(2n − 2) = T(2n − 3) + c(n − 1) both operands are n-1 bits
T(2n − 3) = T(2n − 4) + c(n − 1)
...
T(2) = T(1) + c
Using substitution, we can obtain T(2n) as
T(2n) = 2c ·summation(i) from i=1 to i(12)
which is O(n^2).
Compared to the O(n^3 ) running time of Euclid’s the divide-and-conquer algorithm which is slower
2gcd(a/2, b/2) if a, b are both even ged(a, b/2)if a is odd, b is even...
2,3,4,5,6 please 2. Use the Euclidean algorithm to find the following: a gcd(100, 101) b. ged(2482, 7633) 3. Prove that if a = bq+r, then ged(a, b) = ged(b,r). such that sa tb ged(a,b) for the following pairs 4. Use Bézout's theorem to find 8 and a. 33, 44 b. 101, 203 c. 10001, 13422 5. Prove by induction that if p is prime and plaja... An, then pla, for at least one Q. (Hint: use n = 2 as...
For number 25, can someone explain to me how they got (2^(ab-b)+2^(ab-2b)+2^(ab-3b)+...+(2^(ab-ab)) and how they reached to that conclusion? For number 29, can someone explain to me how "it can't be greater than the greatest common divisor of a-b and b"? I would think that gcd(a, b) would be greater than gcd(a-b, b) because "a" and "b" are bigger than "a-b" and "b" so that confused me. Thank you! 25. Ifn e N and 2n - 1 is prime, then...
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...
T'he goal of this problem is to establish the following remarkable result: Bezout's theorern. If a, be Z50, then 3x, y є Z such that gcd(a, b) = ax + by. Here ged(a, b) denotes the greatest common divisor of a and b (i.e. the largest positive integer that divides both a and b). Throughout this problem, we'll use the notation (a) Write down five numbers that live in 2Z +3Z. What's a simpler name for the set 2Z +3Z?...
I already solved part A and I just need help with part B 1. Matrix Multiplication The product of two n xn matrices X and Y is a third n x n matrix 2 = XY, with entries 2 - 21; = xixYk x k=1 There are n’ entries to compute, each one at a cost of O(n). The formula implies an algorithm with O(nº) running time. For a long time this was widely believed to be the best running...
If someone can help with 3 3) To multiply 2 n bit binary numbers the straightforward way takes (r) time because each digit of each number multiplies each digit of the other number. (The aditions from carying are lower order terms.) Consider the following divide- and-conquer algorithm, which assumes, for simplicity, that n is a power of 2: Split each number into 2 collections of bits, the high order bits and the low order bits. For convenience, call the two...
Question 1. Solving Recursive Relations [3 mark]. A naive multiplication of two matrices of order n requires O(nᵒ) additions. By using a divide and conquer approach, Strassen devised another algorithm that requires T(n) additions where T(n) = 7T(n/2)+cna, where c is a constant independent of n and T(1) = 0 (as multiplying two numbers re- quires no additions). Use the method of backward substitution (introduced in Week 2's lecture) to show that Strassen’s algorithm requires O(nlog27) = O(n2.81) additions, which...
Please prove the 3 theorems, thank you! 7.6 Theorem. Let p be a prime. Then half the numbers not congruent to 0 modulo p in any complete nesidue system modulo p are quadratic residuess modulo p and half are quadratic non-residues modulo p. From clementary school days, we have known that the product of a pos- itive number and a positive number is positive, a positive times a negative is negative, and the product of two negative numbers is positive....
Question 2 (8 marks) (From the DPU textbook, Exercise 2.5) Using the Master theorem or recursion tree methods, solve the following recurence relations and give Θ bound for each of them a) T(n) 9T(n/3) +3n2 12n - 4, where n 21 b) T(n)-T(n-1) + n", where n > 1 and c > 0 c) T(n) = T(Vn) + 1, where n > b and T(b) = 2. Question 3: 10 marks) Suppose we have a subroutine merge2 to merge two...
I have to use the following theorems to determine whether or not it is possible for the given orders to be simple. Theorem 1: |G|=1 or prime, then it is simple. Theorem 2: If |G| = (2 times an odd integer), the G is not simple. Theorem 3: n is an element of positive integers, n is not prime, p is prime, and p|n. If 1 is the only divisor of n that is congruent to 1 (mod p) then...