
a. Argue that the algorithm always terminates, that is, that the algorithm does not call itself
recursively until all eternity. (Hint: Prove that the value of y in Line 9 is less than the value of
x at the beginning of the procedure and draw the right conclusions.)
b. Prove that the algorithm always gives the correct answer. (Hint: Use induction. For the
inductive step, argue that y is divisible by 9 if and only if this is true for x. Use the fact that 9
divides 10^k − 1 for any integer k.)



a. Argue that the algorithm always terminates, that is, that the algorithm does not call itself...
How to prove G(n)=n+1 in this algorithm?
1. if (n 0) 2. return 1 3. else if (n1) f 4. return 2 5. else if (n 2) 6. return 3 7. else if (n3) t 8. return 4 else f 9. int OGnew int[n 11 10. G[O]1 12. G[2]3 13. G[3]4 14. int i:-4 15. while (i<n) t 16. if (i mod 20) else ( 20. return G[n]
1. if (n 0) 2. return 1 3. else if (n1) f...
(10 points) Translate the following algorithm into assembly
language. IF 65 < X THEN X = 9+(X^2) ELSE X = - Y 3.
(10 points) Translate the following algorithm into assembly
language. X=0 FOR K = I TO 5 X=X+5 END_FOR
4. (10 points) Translate the
following algorithm into assembly language. X=0 Y=5 Z=5 WHILE Z = 5
X=X+1 Y=Y-1 Z=X+Y
2. (10 points) Translate the following algorithm into assembly language. IF65 < X THEN X = 9t(X^2) ELSE X...
6.3.1 [10] <§6.2> Consider the following binary search algorithm (a classic divide and conquer algorithm) that searches for a value X in a sorted N-element array A and returns the index of matched entry: BinarySearch(A[0..N−1], X) { low = 0 high = N −1 while (low <= high) { mid = (low + high) / 2 if (A[mid] >X) high = mid −1 else if (A[mid] <X) low = mid + 1 else return mid // found } return −1...
(10 points) Does the following algorithm terminate when x = 9? Show your work. def mystery (x): while (x != 1) : if (x % 2 == 0): X = x/2 else: x = 3 * x + 1
1 1 point Consider the following algorithm for factoring an integer N provided as input (in binary): For i = 2 to [VN.17 i divides N, then output (i, N/). Which of the following statements is true? This algorithm is correct, but it runs in exponential time. This algorithm is not correct, because it will sometimes fail to find a factorization of Neven if N is composite This algorithm runs in sub-linear time, and always factors N it Nis composite...
6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2) will swap the values stored in the variables v1 and v2. Note that % is the modulus operation, and will return the integer remainder r of a/b, i.e., r-a%b Require: Array P with n > 0 values 1: i-1, j-n-l 2: while i<=j do for a=i to j by i do 4: 5: 6: 7: if Pla>Pat 11 and Pla]%2--0 then swap(Plal, Pla+1l) end...
Meet is an operation between zero-one matrices and uses Boolean products (C. Join is an operation between zero-one matrices and uses Boolean products d. Join is an operation between zero-one matrices and uses conjunctions 29. Given set S (-2, -1, 0, 1, 2), R is a relation on S. i. R ( (x, y)| x-y 1} Write R as a set of ordered pairs. (Use roster method to write R as a set of tuples) 3pts ill. and matrix representation...
Please help me figure out why my code is not working properly.I had thought my logic was sound but later found it will run one time through fine however if the user opts to enter another value it will always be returned as an error. #include <iomanip> #include <iostream> #include <cstdlib> using namespace std; int const TRUE = 1; int const FALSE = 0; // declares functions void GetZipcode(); void RunAgain(); int GetSum(char d1, char d2, char d3, char d4,...
You may import the following library functions in your module: from fractions import gcd from math import floor from random import randint You may also use: • the built-in pow() function to compute modular exponents efficiently (i.e., ak mod n can be written in Python as pow(a,k,n)), • the sum() function returns the sum of a list of integers (sum(1,2,3,4) returns 10). problem 1 a. Implement a function invPrime(a, p) that takes two integers a and p > 1 where...