Americas
Europe
Q20E
Expert-verifiedDescribe an algorithm for finding both the largest and the smallest integers in a finite sequence of integers.
Algorithm that produces the minimum(smallest) and maximum(largest) integers in a finite sequence of integers is:
procedure min and max ( : integers with ).
role="math" localid="1668421689261"
for to n
If then .
for to n
If then .
return min, max
Algorithm is a finite sequence of precise instructions that are used for performing a computation or for a sequence of steps.
First, Assume the finite set of integers .
The algorithm called min and max and the input has finite integers .
procedure min and max ( : integers with ).
Initially consider the minimum and maximum as the first term in the list, if the value is not minimum or maximum then the value will be adjusted later in algorithm.
In case the value for second term and term is smaller than the current minimum, then reassign the position of this term to the minimum.
for to n
If then .
Also in case, if the value for second term and term is greater than the current maximum then reassigns the position of this term to the maximum.
for to n
If then .
Combine the above steps then the algorithm is:
procedure min and max ( : integers with ).
for to n
If then .
for to n
If then .
return min, max
94% of StudySmarter users get better grades.
Sign up for free