9. (5 points) Please describe an algorithm that takes as input a list of n integers...
Describe an algorithm that takes as input a list of n integers and produces output the smallest integer in the list.
Problem 3: (5 2 points) Design an algorithm that takes an array of positive integers A of length n and a positive integer T as an input and finds the largest N < T such that N can be written as a sum of some elements of A and returns such a representation of N. The complexity of the algorithms has to be O(nT). For example, for A 3,7, 10 and T 19, the output is 17 7+10, because we...
Consider the following problem: Input: a list of n-1 integers and these integers are in the range of 1 to n. There are no duplicates in list. One of the integers from 1 to n is missing in the list. Output: find the missing integer Let the input array be [2, 4, 1, 6, 3, 7, 8]. Elements in this list are in the range of 1 to 8. There are no duplicates, and 5 is missing. Your algorithm needs...
Describe a non-recursive algorithm that takes a list of distinct integers a_1, a_2, ...., a_n and finds the sum of the primes in the list. Write your answer in pseudo-code or any well-known procedural language like Python, Java, C++, ..... You do not need to write a function to determine whether a number is prime. Assume it is part of your language. E.g. For the list 2, 3, 4, 5, 6, 7, your program should return 17 (because 2 +...
a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n positive integers and determines whether there are two distinct elements of the list that have as their sum a third element of the list. That is, whether there exists i, j.k such that iヂj, i关k,j关k and ai + aj = ak. The algorithm should loop through all triples of elements of the list checking whether the sum of the first two is the third...
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...
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
8. Consider the following algorithm, which finds the sum of all of the integers in a list procedure sum(n: positive integer, a1, a2,..., an : integers) for i: 1 to n return S (a) Suppose the value for n is 4 and the elements of the list are 3, 5,-2,4. List assigned to s as the procedure is executed. (You can list the the values that are values assigned to all variables if you wish) b) When a list of...
5. (570/470 bonus) Design an algorithm whose input is a list of n points, (xu, ) for isks n. Your algorithm should run in O(n) time and determine whether or not the convex hull of these n points is a triangle. Also explain why your algorithm runs in O(n) time.
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...