{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs631hw9solutions

# cs631hw9solutions - CS631 Homework 9 solutions Page 513#8...

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

CS631 Homework 9 solutions Page 513, #8 Trace insertion sort on the following data. Underlined values have just been moved there. Initial array: 20 80 40 25 60 40 Pass 1: 20 80 40 25 60 40 Pass 2: 20 40 80 25 60 40 Pass 3: 20 25 40 80 60 40 Pass 4: 20 25 40 60 80 40 Pass 5: 20 25 40 40 60 80 The second 40 is in italics to distinguish it from the first. A sort that keeps the relative position of equal values is called stable . Whether insertion sort is stable depends on one line – if, in the comparison to decide whether to move a value to the left, you have strictly greater (>) then it is stable, while if you have greater or equal (>=) then it won’t be stable. So the stability depends on the presence of the = character. Page 513, #8 Trace selection sort on the following data. Underlined values have just been swapped. Note: this solution uses selection and swap to first of the min, rather than selection and swap to last of max. Initial array: 07 12 24 04 19 32 Pass 1: 04 12 24 07 19 32 Pass 2: 04 07 24 12 19 32 Pass 3: 04 07 12 24 19 32 Pass 4: 04 07 12 19 24 32 Pass 5: 04 07 12 19 24 32 Page 513, #11. Apply selection sort, bubble sort and insertion sort to a. An inverted array (8 6 4 2) Initial array: 8 6 4 2 Selection Pass 1: 2 6 4 8 Pass 2: 2 4 6 8 Pass 3: 2 4 6 8 Swapping 6 and 8 not required

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 / 3

cs631hw9solutions - CS631 Homework 9 solutions Page 513#8...

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

View Full Document
Ask a homework question - tutors are online