In: Advanced Math
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.
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!