Sorting Develop a sorting algorithm Computer Science Sorting Develop a sorting algorithm
Learning Objectives Be able to complete the Tally Array program. Be able to develop a strategy to put information in order using an array.
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 http://www.dat.ruc.dk/~keld/algoritmik_e99/Applets/Chap08/Bubble/BubbleSort.html 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}
Sorting Program Option #1 Option #2 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 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.