Question

In: Advanced Math

Suppose that the array X consists of real numbers X[1], X[2], …, X[N]. Write a pseudocode...

Suppose that the array X consists of real numbers X[1], X[2], …, X[N]. Write a pseudocode program to compute the minimum of these numbers.

Solutions

Expert Solution

Pseudocode is given below. Sentences starting with % are comments meant for better understanding of pseudocode

function m=min(X)

If X is empty, return exception "no minimum for empty array"

If length(X)=1, m=X[1] %return first element if array has only one element

Else if length(X)>1, m=X(1) %define the minimum to be the first number temporarily

For k=2 to N %traverse the length of the remaining array

         if X[k]<m then m=X[k]

end %what this for loop does is while traversing array, it checks if the current element is less than the previous     % minimum element, and if it is, then it makes the current element as our new minimum element

Return m

Please don't forget to rate positively if you found this response helpful. Feel free to comment on the answer if some part is not clear or you would like to be elaborated upon. Thanks and have a good day!


Related Solutions

Suppose that each row of an n × n array A consists of 1’s and 0’s...
Suppose that each row of an n × n array A consists of 1’s and 0’s such that, in any row of A, all the 1’s come before any 0’s in that row. Assuming A is already in memory, describe a method running in O(n log n) time (not O(n2) time!) for counting the number of 1’s in A.
Given an array A of n distinct real numbers, we say that a pair of numbers...
Given an array A of n distinct real numbers, we say that a pair of numbers i, j ∈ {0, . . . , n−1} form an inversion of A if i < j and A[i] > A[j]. Let inv(A) = {(i, j) | i < j and A[i] > A[j]}. Answer the following: (a) How small can the number of inversions be? Give an example of an array of length n with the smallest possible number of inversions. (b)...
Suppose you are provided with an array of integer values. Write pseudocode for a program to...
Suppose you are provided with an array of integer values. Write pseudocode for a program to determine how many unique values are in the array. Your solution should require time that is linearithmic in the size of the array. (For example, if the array contains the values {1,3,4,1,2}, the answer is "4", because the array contains the values 1, 2, 3, and 4)
Suppose the function  g(x) has a domain of all real numbers except x = −2 . The...
Suppose the function  g(x) has a domain of all real numbers except x = −2 . The second derivative of g(x) is shown below. g ''(x) = (x−1)(x + 3) (x + 2)3 (a) Give the intervals where   g(x) is concave down. (Enter your answer using interval notation. If an answer does not exist, enter DNE.) (b) Give the intervals where   g(x) is concave up. (Enter your answer using interval notation. If an answer does not exist, enter DNE.) (c) Find...
algorithm binarySearch input bottom, top: a number    a: array a[0] to a[n-1] of numbers    x: a...
algorithm binarySearch input bottom, top: a number    a: array a[0] to a[n-1] of numbers    x: a number output result: true if x in a false otherwise Sideeffect NA Plan if (top < bottom) result := false else // get the middle of the array (refining) middle := (top - bottom)/2 + bottom (refining by +1 or -1 or integer division …) // example what is midpoint between 6 and 8 // (8-6)/2 = 1 we need to add 6 to...
In MATLAB Write a function to create an array of N numbers with a normal distribution....
In MATLAB Write a function to create an array of N numbers with a normal distribution. Call that from a script to create 1000 numbers, with a mean of 50 and a sigma of 10.
Fibonacci Write pseudocode to calculate F(n) Write pseudocode to construct a vector of the first n...
Fibonacci Write pseudocode to calculate F(n) Write pseudocode to construct a vector of the first n numbers in the Fibonacci sequence. Write a function: fibo(n = 1){ # Your code here } which takes one parameter ​n​ and returns the ​nth​ fibonacci number. Use the function you wrote to calculate the 58th Fibonacci number. Include your R code in your report The Fibonacci sequence (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...) is defined as F(1) =...
Suppose P (x, y) means “ x and y are real numbers such that x +...
Suppose P (x, y) means “ x and y are real numbers such that x + 2y = 5 .” Determine whether the statement is true for ∀x∃yP(x,y) and ∃x∀yP(x,y)
The following is the pseudocode of algorithm that searches a sorted array of n items by...
The following is the pseudocode of algorithm that searches a sorted array of n items by dividing it into three sub arrays of almost n/3 items (7pt). Hint: refer Mergesort algorithm) Input: Sorted array of Keys(A) indexed from 1 to n. Output: Location, the Location of K in array A (hint: return 0 if K is no in A) index location3 (int A[1…n ], index L, index H) { index m1, m2; if (L > H) return 0; else   ...
1. Let α < β be real numbers and N ∈ N. (a). Show that if...
1. Let α < β be real numbers and N ∈ N. (a). Show that if β − α > N then there are at least N distinct integers strictly between β and α. (b). Show that if β > α are real numbers then there is a rational number q ∈ Q such β > q > α. *********************************************************************************************** 2. Let x, y, z be real numbers.The absolute value of x is defined by |x|= x, if x ≥...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT