csc110.feb.25

csc110.feb.25 - and sorted list as 8) 3. Repeat same...

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

View Full Document Right Arrow Icon
February 25, 2008 Test 3/5/08 on chap 1-3 Review Monday Bs search used for ordered list only- for unordered list, must use sequential search.  Binary search – ordered lists – theta(log2N) Sorting algorithm  – (pg 89) N=5 (size of list) 5 7 2 8 3I* UNSORTED SORTED (unsorted list)     *Marker at end of list  1. Find largest for unsorted list 2. Sort largest as last element in unsorted list. Swap largest element number of the  unsorted list with the last element of the unsorted list.  (rewrite unsorted list as 5, 7, 2, 3 
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: and sorted list as 8) 3. Repeat same process – choose largest # (7) – (rewrite list as 5, 3, 2, 7 -> unsorted 5, 3, 2 and sorted list 7, 8 4. Next number is 5, swap with last element, 2, move five to sorted list 5. Next number is 3, already sorted, swap with itself – move to sorted list 6. 2 swaps with itself (last number in unsorted list)move 2 to sorted list 7. Finally – I* 2, 3, 5, 7, 8 Initially, all numbers are left of marker, finally all numbers are right of marker and are sorted. Chap 3 slide 20 – selection sort...
View Full Document

This note was uploaded on 04/17/2008 for the course CSC 110 taught by Professor Gao during the Spring '08 term at Eastern CT.

Ask a homework question - tutors are online