{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2-3_6 - Solution to Exercise 2.3-6 The while loop of lines...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Solution to Exercise 2.3-6 The while loop of lines 5—7 of procedure lNSERTION—SORT scans backward through the sorted array A[1 . . j — 1] to find the appropriate place for A[ j]. The hitch is that the loop not only searches for the proper place for A[ j], but that it also moves each of the array elements that are bigger than A[j] one position to the right (line 6). These movements can take as much as @( j) time, which occurs when all the j — 1 elements preceding AU] are larger than A[j]. We can use binary search to improve the running time of the search to @(lg j), but binary search will have no effect on the running time of moving the elements. Therefore, binary search alone cannot improve the worst—case running time of INSERTION—SORT to 80’: lg n). ...
View Full Document

{[ snackBarMessage ]}