Log In Start studying!

Select your language

Suggested languages for you:
Answers without the blur. Sign up and see all textbooks for free! Illustration

Q20E

Expert-verified
Discrete Mathematics and its Applications
Found in: Page 202
Discrete Mathematics and its Applications

Discrete Mathematics and its Applications

Book edition 7th
Author(s) Kenneth H. Rosen
Pages 808 pages
ISBN 9780073383095

Answers without the blur.

Just sign up for free and you're in.

Illustration

Short Answer

Describe 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 x1,x2,x3 is:

procedure min and max ( x1,x2,x3 : integers with n1 ).

role="math" localid="1668421689261" min:=x1max:=x1

for i:=2 to n

If xi<min then min:=xi .

for i:=2 to n

If xi>max then max:=xi .

return min, max

See the step by step solution

Step by Step Solution

Step 1: algorithm

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 x1,x2,.....xn .

The algorithm called min and max and the input has finite integers x1,x2,.....xn .

Step 2: Minimum and Maximum

procedure min and max ( x1,x2,.....xn : integers with n1 ).

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.

min:=x1max:=x1

Step 3: determine the minimum and maximum

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 i:=2 to n

If xi<min then min:=xi .

Also in case, if the value for second term and nth term is greater than the current maximum then reassigns the position of this term to the maximum.

for i=2 to n

If xi>max then max:=xi .

Step 4: Combine above steps

Combine the above steps then the algorithm is:

procedure min and max ( x1,x2,.....,xn : integers with n1 ).

min:=x1max:=x1

for i:=2 to n

If xi<min then min:=xi .

for i:=2 to n

If xi>max then max:=xi .

return min, max

Recommended explanations on Math Textbooks

94% of StudySmarter users get better grades.

Sign up for free
94% of StudySmarter users get better grades.