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 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...
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) =...
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...
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)
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 ≥...
Suppose that x is real number. Prove that x+1/x =2 if and only if x=1. Prove...
Suppose that x is real number. Prove that x+1/x =2 if and only if x=1. Prove that there does not exist a smallest positive real number. Is the result still true if we replace ”real number” with ”integer”? Suppose that x is a real number. Use either proof by contrapositive or proof by contradiction to show that x3 + 5x = 0 implies that x = 0.
The function f(x) = x^2 (x^2 − 2x − 36) is defined on all real numbers....
The function f(x) = x^2 (x^2 − 2x − 36) is defined on all real numbers. On what subset of the real numbers is f(x) concave down?
Suppose A is an mxn matrix of real numbers and x in an nx1 column vector....
Suppose A is an mxn matrix of real numbers and x in an nx1 column vector. a.) suppose Ax=0. Show that ATAx=0. b.)Suppose ATAx=0. show Ax=0. c.) by part a and b, we can conclude that Nul(A) = Nul(ATA), and thus dim(Nul A) = dim(Nul(ATA)), and thus nullity(A) = nullity(ATA). prove the columns of A are linearly independent iff ATA is invertible.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT