• :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

Q51E

Expert-verified
Discrete Mathematics and its Applications
Found in: Page 204
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

When a list of elements is in close to the correct order, would it be better to use an insertion sort or its variation described in Exercise 50?

Hence, it is concluded that the changed insertion sort algorithm will work nicely if the list is close to the correct order.

See the step by step solution

Step by Step Solution

Step 1:

  • Insertion sort Algorithm: the insertion sort compares this second element with the first element and inserts it before the first element if it does not exceed the first element hence the first two elements are in the correct order.
  • Then, the third element is compared with the first element and if it is larger than the first element it is compared with the second element, and this is inserted on the correct position among the first three elements. Hence, we will continue this procedure till the sort is complete.
  • Now, see both the algorithm one by one.

Step 2:

Now, the required insertion sort algorithm is:

Procedure insertionsort ( a1,a2,...,an: : real numbers, n2 )

For j : = 2 to n

i : = 1

While aj>aii:=i+1m:=aj

For k = 0 to j - i - 1

aj-k=aj-k-1ai:=m

{ a1,a2,...,an is in increasing order}

Step 3:

Now, see the changed insertion sort algorithm:

Procedure insertionsort ( a1,a2,....,an: : real numbers, n2 )

For j : = 2 to n

i : = j - 1

While aj>ai and i>0i:=i-1m:=aj

For k = 0 to j - i - 1 to 0

aj-k=aj-k-1ai:=m

{ a1,a2,...,an is in increasing order}

Step 4:

So, from the above two algorithm its is concluded that the use of linear search at the time of insertion of element will make the process fast if the elements are close to the correct order and the reason behind the statement is that the linear search goes from back to front.

Recommended explanations on Math Textbooks

94% of StudySmarter users get better grades.

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