• :00Days
  • :00Hours
  • :00Mins
  • 00Seconds
A new era for learning is coming soonSign up for free
Log In Start studying!

Select your language

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

Q21E

Expert-verified
Discrete Mathematics and its Applications
Found in: Page 203
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 that puts the first three terms of a sequence of integers of arbitrary length in increasing order.

Algorithm that that puts the first three terms of a sequence of integers of arbitrary length in increasing order is:

procedure order first three ( x1,x2,x3,...,xn : integers with n3 ).

If x1<x2

then interchange x1 and x2 i.e., x1<x2

If x2<x3

Then interchange x2 and x3 i.e., x2<x3

return x1<x2<x3

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 sequence of integers x1,x2,x3,...,xn .

The algorithm called order first three and the input has finite integers x1,x2,x3,...,xn .

Step 2: Interchange for first and second term

procedure order first three ( x1,x2,x3,...,xn : integers with n3 ).

Use the variable to interchange variables.

First check if the integer x1 and x2 are in increasing order, if x1 and x2 are not in increasing order then interchange the variables.

If x1>x2

then interchangex1 and x2 i.e., x1<x2

Step 3: Interchange for second and third term

Now check if the integer x2 and x3 are in increasing order, if x2 and x3 are not in increasing order then interchange the variables.

If x2>x3

Then interchange x2 and x3 i.e., x2<x3

Step 4: Combine the above steps

Combine the above steps, the algorithm is:

procedure order first three ( x1,x2,x3,...,xn : integers with n3 ).

If x1>x2

then interchange x1 and x2 i.e., x1>x2

If x2>x3

Then interchange x2 and x3 i.e., x2>x3

return x1<x2<x3

Recommended explanations on Math Textbooks

94% of StudySmarter users get better grades.

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