1 1 point Consider the following algorithm for factoring an integer N provided as input (in...
Consider the following algorithm. ALGORITHM Enigma(A[0.n - 1]) //Input: An array A[0.n - 1] of integer numbers for i leftarrow 0 to n - 2 do for j leftarrow i +1 to n - 1 do if A[i] = = A[j] return false return true a) What does this algorithm do? b) Compute the running time of this algorithm.
17. Consider the following algorithm: procedure Algorithm(n: positive integer; di,d2.. ,dn: distinct integers) for 1 to n-1 for 1 to n-k if ddi+ then interchange di and di+ print(k, I, d,ddn-1, dn) (a) |3 points Assume that this algorithm receives as input the integer-6 and the corresponding input sequence 41 36 27 31 17 20 Fill out the table below ds (b) 1 point Assume that the algorithm receives the same input values as in part a). Once the algo-...
8. [10 points) Consider the following algorithm procedure Algorithm(: integer, n: positive integer; 81,...a s integers with vhilei<r print (l, r, mı, arn, 》 if z > am then 1:= m + 1 if za then anstwer-1 return answer 18 and the (a) Assume that this algorithm receives as input the numbersz-32 and corresponding sequence of integers 2 | 3 1 1 4151617| 8| 9 | 10 İ 11 İ 12 | 13 | 14|15 | 16 | 17 |...
2. Find 11644 mod 645 Use the following algorithm and show work! procedure modularExponentiation(b: integer, n = (ak-1ak-2...a1a0)2, m:positive integer) x:= 1 power := b mod m for i = 0 to k-1 If ai = 1 then x:= (x⋅power) mod m power := (power⋅power) mod m return x ( x equals bn mod m) Note: in this example m = 645, ai is the binary expansion of 644, b is 11.
9. (5 points) Please describe an algorithm that takes as input a list of n integers and finds the number of negative integers in the list. 10. (5 points) Please devise an algorithm that finds all modes. (Recall that a list of integers is nondecreasing if each term of the list is at least as large as the preceding term.) 11. (5 points) Please find the least integer n such that f() is 0(3") for each of these functions f()...
In this problem you will implement an algorithm for computing all the square roots of a congruence class in ℤ/nℤ, given a complete factorization of n into its distinct prime factor powers (assuming all the prime factors are in 3 + 4ℤ). a) Implement a Python function sqrtsPrime(a, p) that takes two arguments: an integer a and a prime number p. You may assume that a and p are coprime. If p is not in 3 + 4ℤ or a...
1. Design and write a Divide& Conquer algorithm that, given an array A of n distinct integers which is already sorted into ascending order, will find if there is some i such that Ali] in worst-case 0(log n) time.
Explain why the following algorithm is complete, correct, and finite. Input: a list of n distinct integers a0 to an-1 ordered from least to greatest and an integer x Output: the index in the list at which x is found, or -1 if x is not found Procedure: i = 0 while (i <= n-1 and x != ai) i = i + 1 if i < n then location = i else location = -1 return location
9. [10 points) Consider the following algorithm: procedure Algorithm(n: positive integer; ddd: distinet integers) for k:=1 to n-1 for 1-1 to n-k print(k, I, di,da...-1,dn) if ds dti then interchange dy and d (a) Assume that this algorithm receives as input the integer n 6 and the input sequence 하하하하하하, Miss ^-ruteae rehen i12|3141516 Fill out the table below: ds ds (b) Assume that the algorithm receives the same input values as in part a). Once the algorithm finishes, what...
Show that the following algorithm is correct, complete, and finite. Input: a list of n distinct positive integers a0, ..., an-1 Output: The largest even integers in the list, or 0 if there are no even integers Procedure: even= 0 for (i=0, i<n, i+=1) if ai%2 == 0 and ai > even even = ai return even