Computer Science Sorting Pre-Test Discussion/program Bubble and Selection Sort (If time)
Learning Objectives Develop two algorithms for putting information in order. Be introduced to measuring the efficiency of an algorithm
Sorting How do you put things in order? (Low to high) Pseudo-Code Develop a sorting algorithm
Bubble Sort Low High 8 2 6 9 21 1 Speed: O(n2) Stability: Stable How it works: Check- Switch Show it after each pass Low High 8 2 6 9 21 1
Bubble Sort {This is just the code for Bubble Sort} for pass:= 1 to (size -1) do begin for check:= 1 to size-1 do if TheArray[check]>TheArray[check+1] then dummy:= TheArray[check]; TheArray[check]:= TheArray[check+1]; TheArray[check+1]:= dummy; End; {Of the if and the for check loop} end;{Of the for pass loop}
Bubble Sorting Program Option #1 Randomly generate 100 scores from 1 to 50. Show the numbers before they are sorted show the numbers after they are sorted. Push: Show graphically the numbers being sorted. Push: Change it to 5000, 50000, 5000000 numbers and time how long it takes for them to sort. Push: Improve the efficiency of the sort. Option #2 Input 10 race times for the 100 meter dash. (enter the time as seconds) Output: The times sorted from fastest to slowest. Push: Enter the name that goes with each time, and show a chart of names and times for the race.