{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW1 Solution - Solution to HW1 Solution to Exercise 2.3-6...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Solution to HW1 Solution to Exercise 2.3-6 The while loop of lines 5-7 of procedure I NSERTION -S ORT 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-1elements preceding A[j] are larger than A[j]. We can use binary search to improve the running time of the search to Θ (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 I
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

{[ snackBarMessage ]}