1. Input: n, number of integers
2. Intialize int A[n], where n is the size of array..
3. For int i=1 to n
Input : A[i]
4. End Loop
5. Intialize int temp=A[0], whichwill store smallest integer in the list.
6. For int j=1 to n
if A[i]<temp
temp=A[i]
7. End if
8. End Loop
9. Output: Smallest Integer in list is: temp
Describe an algorithm that takes as input a list of n integers and produces output the...
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()...
Describe an algorithm that takes as input two sorted lists of length n and m and an integer k and outputs the kst smallest element in their union. You can assume both lists contain integers and all entries are different.
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...
Linda creates an algorithm that takes an input sequence S and produces an output sequence T that is a sorting of the n elements of S. a) In Java, give an algorithm, isSorted, for testing in O(n) time if T is sorted. b) Explain why the algorithm isSorted is not sufficient to prove a particular output T of Linda's algorithm is a sorting of S. c) Describe what additional information Linda's algorithm could output so that her algorithm's correctness could...
Write a function findEvens that takes an integer, n, as input and returns the list of even integers between 1 and n. Ex. Input: 10 Output: [2,4,6,8,10] Write a function sortList that takes in a list of strings and returns a list of those strings now sorted and lowercase. Ex. Input: [‘ABE’,’CAD’,’gaB’] Output: [‘abe’,’acd’,’abg’] Both done in Python
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...
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...
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
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
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 +...