Discrete Mathematics and Its Applications, Seventh Edition

Published by McGraw-Hill Education
ISBN 10: 0073383090
ISBN 13: 978-0-07338-309-5

Chapter 3 - Section 3.1 - Algorithms - Exercises - Page 203: 46

Answer

$n-1$

Work Step by Step

$Insertion$ $sort$ compare first the second element with the first and correctly sorts these two numbers. Then it takes the next element and correctly inserts it in the part of the string that we already know is correctly sorted, and so on. $First$ $pass$: we compare the first two elements and thus we make 1 comparison. $Second$ $pass$: We compare the third element with the first element (no other comparisons are needed as the element to insert at the beginning of the already sorted list), thus make 1 comparison. $Third$ $pass$: We compare the fourth element with the first element, thus we made 1 comparison. $kth$ $pass$: On the kth pass, we compare the $k+1th$ element with the first terms and thus we make 1 comparison. Insertion algorithm will step if only 1 element is remaining. If the original list contains n elements, the insertion algorithm will then stop when the $n -1th$ pass (when the nth element is compared with the last n-1 terms). comparisons $=1+1+1+\ldots+1=\sum_{i=1}^{n-1} 1=n-1$
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.