CS 100 M Lecture 25 - 25. Efficiency Insertion sort vs....

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

View Full Document Right Arrow Icon
25. Efficiency Insertion sort vs. merge sort Timing with tic toc Time efficiency vs. memory efficiency Announcements: - P6 will be posted today, due 11/29 - Final exam conflict? Email Kelly Patwell with complete exam schedule
Background image of page 1

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

View Full DocumentRight Arrow Icon
Merge Sort
Background image of page 2
Merge Sort
Background image of page 3

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

View Full DocumentRight Arrow Icon
Merge Sort
Background image of page 4
Merge Sort
Background image of page 5

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

View Full DocumentRight Arrow Icon
Merge Sort
Background image of page 6
Merge Sort
Background image of page 7

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

View Full DocumentRight Arrow Icon
Merge Sort
Background image of page 8
Merge Sort
Background image of page 9

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

View Full DocumentRight Arrow Icon
Merge Sort
Background image of page 10
Insertion Sort • Given a sorted array x , insert a number y such that the result is sorted 2 3 6 9 8
Background image of page 11

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

View Full DocumentRight Arrow Icon
Insertion Sort • Given a sorted array x , insert a number y such that the result is sorted 2 3 6 9 8 2 3 6 9 8
Background image of page 12
Insertion Sort • Given a sorted array x , insert a number y such that the result is sorted 2 3 6 9 8 2 3 6 9 8 2 3 6 9 8
Background image of page 13

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

View Full DocumentRight Arrow Icon
2 3 6 9 8 2 3 6 9 8 2 3 6 9 8
Background image of page 14
4 2 3 6 9 8 2 3 6 9 8 2 3 6 9 8
Background image of page 15

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

View Full DocumentRight Arrow Icon
4 2 3 6 9 8 4 2 3 6 9 8 2 3 6 9 8 2 3 6 9 8
Background image of page 16
4 2 3 6 9 8 4 2 3 6 9 8 4 2 3 6 9 8 2 3 6 9 8 2 3 6 9 8
Background image of page 17

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

View Full DocumentRight Arrow Icon
4 2 3 6 9 8 4 2 3 6 9 8 4 2 3 6 9 8 4 2 3 6 9 8 2 3 6 9 8 2 3 6 9 8
Background image of page 18
4 2 3 6 9 8 4 2 3 6 9 8 4 2 3 6 9 8 4 2 3 4 9 8 6 2 3 6 9 8 2 3 6 9 8 2 3 6 9 8
Background image of page 19

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

View Full DocumentRight Arrow Icon
Develop the insertion sort algorithm • The sorted segment grows one element at a time—need to keep track of the length of the sorted segment, say, index i • What is the simpliest (shortest) case? A list of length 1, so start with i=1 • Inserting the (i+1)th element requires a series of swaps: swap until the element to be inserted is at the correct place a while -loop 2 3 6 9 8 4 2 3 6 9 8 4 2 3 6 9 8 4 2 3 6 9 8 4 2 3 4 9 8 6 i=5 i=6
Background image of page 20
9 6 3 4 8 2 i=1: insert x(2) into x(1:1)
Background image of page 21

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

View Full DocumentRight Arrow Icon
9 6 3 4 8 2 i=1: insert x(2) into x(1:1) 6 9 3 4 8 2
Background image of page 22
9 6 3 4 8 2 i=1: insert x(2) into x(1:1) 6 9 3 4 8 2 i=2: insert x(3) into x(1:2)
Background image of page 23

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

View Full DocumentRight Arrow Icon
9 6 3 4 8 2 i=1: insert x(2) into x(1:1) 6 9 3 4 8 2 i=2: insert x(3) into x(1:2) 6 9 3 4 8 2
Background image of page 24
9 6 3 4 8 2 i=1: insert x(2) into x(1:1) 6 9 3 4 8 2 i=2: insert x(3) into x(1:2) 6 9 3 4 8 2 6 9 3 4 8 2
Background image of page 25

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

View Full DocumentRight Arrow Icon
Image of page 26
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/23/2008 for the course CS 100 taught by Professor Fan/vanloan during the Spring '07 term at Cornell University (Engineering School).

Page1 / 41

CS 100 M Lecture 25 - 25. Efficiency Insertion sort vs....

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online