404_lecture1b_F11

404_lecture1b_F11 - Text Chapters 1, 2 Ch t 1 Sorting...

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Text Chapters 1, 2 Ch t 1 Sorting Algorithm: Algorithm: well-defined wellsteps computational procedure that transforms input into output for the computer to follow to solve a problem instance Sorting P bl S ti Problem: Input: A sequence of n numbers < a 1 , a 2 , L , a n > Output: A permutation (reordering) < a '1 , a ' 2 , L , a ' n > of the input sequence such that: a '1 a ' 2 L a ' n Insertion Sort Animation Finding a place for item with value 5 in position 1: Swap item in position 0 with item in position 1. Former link... http://www.cs.brockport.edu/cs/java/apps/sorters/insertsortaniminp.html Insertion Sort Animation Positions 0 through 1 are now in non-decreasing order. non- Insertion Sort Animation Finding a place for item with value 1 in position 2: Swap item in position 1 with item in position 2. Insertion Sort Animation Finding a place for item with value 1: Swap item in position 0 with item in position 1. Positions 0 through 2 are now in non-decreasing order. non- Insertion Sort Animation Finding a place for item with value 3 in position 3: Swap item in position 2 with item in position 3. Insertion Sort Animation Finding a place for item with value 3: Swap item in position 1 with item in position 2. Insertion Sort Animation Positions 0 through 3 are now in non-decreasing order. non- Insertion Sort Animation Finding a place for item with value 2 in position 4: Swap item in position 3 with item in position 4. Insertion Sort Animation Finding a place for item with value 2: Swap item in position 2 with item in position 3. Insertion Sort Animation Finding a place for item with value 2: Swap item in position 1 with item in position 2. Insertion Sort Animation Positions 0 through 4 are now in non-decreasing order. non- Insertion Sort Animation Finding a place for item with value 6 in position 5: Swap item in position 4 with item in position 5. Insertion Sort Animation Positions 0 through 5 are now in non-decreasing order. non- Insertion Sort Animation Finding a place for item with value 4 in position 6: Swap item in position 5 with item in position 6. Insertion Sort Animation Finding a place for item with value 4: Swap item in position 4 with item in position 5. Insertion Sort Animation Positions 0 through 6 are now in non-decreasing order. non- Insertion Sort Animation Finding a place for item with value 7 in position 7: Swap item in position 6 with item in position 7. Insertion Sort Animation Positions 0 through 7 are now in non-decreasing order. non- Insertion Sort Animation Positions 0 through 7 are now in non-decreasing order. non- Insertion Sort Animation Positions 0 through 7 are now in non-decreasing order. non- ...
View Full Document

This note was uploaded on 02/13/2012 for the course CS 91.404 taught by Professor Dr.karendaniels during the Fall '09 term at UMass Lowell.

Ask a homework question - tutors are online