{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW1 Solution

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

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

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

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}