# lec8 - MIT OpenCourseWare http/ocw.mit.edu 6.006...

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

MIT OpenCourseWare http://ocw.mit.edu 6.006 Introduction to Algorithms Spring 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms .

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

View Full Document
Lecture 8 Sorting I: Heaps 6.006 Spring 2008 Lecture 8: Sorting I: Heaps Lecture Overview Review: Insertion Sort and Merge Sort Selection Sort Heaps Readings CLRS 2.1, 2.2, 2.3, 6.1, 6.2, 6.3 and 6.4 Sorting Review Insertion Sort 5 2 4 6 1 3 5 2 4 6 1 3 2 1 3 4 5 6 4 2 5 6 1 3 4 2 5 6 1 3 2 1 4 5 6 3 key θ(n 2 ) algorithm Figure 1: Insertion Sort Example Merge Sort Divide n -element array into two subarrays of n/ 2 elements each. Recursively sort sub-arrays using mergesort. Merge two sorted subarrays. 1
Lecture 8 Sorting I: Heaps 6.006 Spring 2008 2 4 5 7 2 3 6 1 1 2 2 3 4 5 6 7 L A R θ(n) time θ(n) auxiliary space 2 4 5 7 2 3 6 1 A[1: n/2] A[n/2+1: n] want sorted A[1: n] w/o auxiliary space?? Figure

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 ]}

### Page1 / 6

lec8 - MIT OpenCourseWare http/ocw.mit.edu 6.006...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online