Data Structures - CSCI 102 Selection Sort Keep the list separated into sorted and unsorted sections Start by finding the minimum & put it at the front of the list Repeat by finding the minimum in the sublist On the i th iteration, find the i th smallest number in the list Keep going until you reach the end of the list 4 Copyright © William C. Cheng
5 Copyright © William C. Cheng Data Structures - CSCI 102 Selection Sort First pass through the list
Data Structures - CSCI 102 Selection Sort First pass through the list Minimum 6 Copyright © William C. Cheng
7 Copyright © William C. Cheng Data Structures - CSCI 102 Selection Sort First pass through the list MinimumOutput
Data Structures - CSCI 102 Selection Sort First pass through the list Swap 8 Copyright © William C. Cheng
9 Copyright © William C. Cheng Data Structures - CSCI 102 Selection Sort First pass through the list UnsortedSorted
Data Structures - CSCI 102 Selection Sort 2nd pass through the list Minimum 10 Copyright © William C. Cheng
Data Structures - CSCI 102 Selection Sort 2nd pass through the list Minimum Stay 11 Copyright © William C. Cheng
12 Copyright © William C. Cheng Data Structures - CSCI 102 Selection Sort 2nd pass through the list Minimum Stay SortedUnsorted
13 Copyright © William C. Cheng Data Structures - CSCI 102 Selection Sort 3rd pass through the list MinimumOutput
Data Structures - CSCI 102 Selection Sort 3rd pass through the list Minimum Output Swap 14 Copyright © William C. Cheng
15 Copyright © William C. Cheng Data Structures - CSCI 102 Selection Sort 3rd pass through the list Minimum Output SortedUnsorted Swap
16 Copyright © William C. Cheng Data Structures - CSCI 102 Selection Sort 4th pass through the list MinimumOutput
Data Structures - CSCI 102 Selection Sort 4th pass through the list Minimum Output Swap 17 Copyright © William C. Cheng
18 Copyright © William C. Cheng Data Structures - CSCI 102 Selection Sort 4th pass through the list Minimum Output SortedUnsorted Swap
19 Copyright © William C. Cheng Data Structures - CSCI 102 Selection Sort 5th pass through the list No 5th pass needed The last element must be sorted by now
20 Data Structures - CSCI 102 Copyright © William C. Cheng Selection Sort void selectionSort(vector & numbers) { for(int i=0; i < numbers.size()-1; i++) { //find the minimum int minValue = numbers[i] int minIndex = i; for(int j=i+1; j < numbers.size(); j++) { if(numbers[j] < minValue) { minValue = numbers[j]; minIndex = j; }}}} //move the minimum into the sorted section swap(numbers[i],numbers[minIndex]); }}}}
None, O(n ) O(n ) What’s the best case scenarios? What’s the Big O for this case? Selection Sort 22 Data Structures - CSCI 102 Copyright © William C. Cheng Selection Sort What’s the worst case scenario? What’s the Big O for this case? What’s the overall Big O? What are the problems with selection sort? Still too many comparisons
Bubble Sort 23 Data Structures - CSCI 102 Copyright © William C. Cheng Bubble Sort Compare adjacent numbers If they’re out of order swap them Otherwise leave them be Loop through the list until there are no more swaps to make Smaller numbers slowly "bubble" up toward the top of the list
24 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort First pass through the list
Data Structures - CSCI 102 Bubble Sort First pass through the list Swap 25 Copyright © William C. Cheng
26 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort First pass through the list Swap
27 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort First pass through the list
Data Structures - CSCI 102 Bubble Sort First pass through the list Stay 28 Copyright © William C. Cheng
29 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort First pass through the list
Data Structures - CSCI 102 Bubble Sort First pass through the list Swap 30 Copyright © William C. Cheng
31 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort First pass through the list Swap
32 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort First pass through the list
Data Structures - CSCI 102 Bubble Sort First pass through the list Swap 33 Copyright © William C. Cheng
34 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort First pass through the list Swap
35 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort First pass through the list
36 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort First pass through the list
37 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 2nd pass through the list
Data Structures - CSCI 102 Bubble Sort 2nd pass through the list Stay 38 Copyright © William C. Cheng
39 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 2nd pass through the list
Data Structures - CSCI 102 Bubble Sort 2nd pass through the list Swap 40 Copyright © William C. Cheng
41 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 2nd pass through the list Swap
42 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 2nd pass through the list
Data Structures - CSCI 102 Bubble Sort 2nd pass through the list Stay 43 Copyright © William C. Cheng
44 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 2nd pass through the list
45 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 2nd pass through the list
46 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 3rd pass through the list
Data Structures - CSCI 102 Bubble Sort 3rd pass through the list Swap 47 Copyright © William C. Cheng
48 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 3rd pass through the list Swap
49 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 3rd pass through the list
Data Structures - CSCI 102 Bubble Sort 3rd pass through the list Stay 50 Copyright © William C. Cheng
51 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 3rd pass through the list
52 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 4th pass through the list
Data Structures - CSCI 102 Bubble Sort 4th pass through the list Stay 53 Copyright © William C. Cheng
54 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 4th pass through the list
55 Copyright © William C. Cheng Data Structures - CSCI 102 Bubble Sort 4th pass through the list During the 4th pass, nothing got swapped This means that the unsorted part is actually sorted No more pass needed
56 Data Structures - CSCI 102 Copyright © William C. Cheng Bubble Sort void naiveBubbleSort(vector & numbers) { for(int i=0; i < numbers.size()-1; i++) { for(int j=0; j < numbers.size()-1; j++) { if(numbers[j] > numbers[j+1]) { swap(numbers[j],numbers[j+1]); }}}}}}}} Naive Bubble Sort
BubbleSort(n) = O(n ) 2) Take advantage of the fact that on the i iteration, 58 Data Structures - CSCI 102 Copyright © William C. Cheng Bubble Sort Naive Bubble Sort What’s the Big O for this bubble sort? How could we improve this algorithm? 2 1) Make it terminate early if the sorting is already done th the last i elements are sorted
List in Reverse Order, O(n ) O(n ) 61 Data Structures - CSCI 102 Copyright © William C. Cheng Bubble Sort Better Bubble Sort What’s the overall Big O? What are the problems with bubble sort? What’s the best case scenarios? What’s the Big O for this case? What’s the worst case scenario? What’s the Big O for this case? Already Sorted, O(n) 2 2 Too much swapping! Too many comparisons!
On the i iteration, i items will be sorted Keep the list separated into sorted and unsorted sections Insertion Sort 62 Data Structures - CSCI 102 Copyright © William C. Cheng Insertion Sort Take each number in the unsorted portion of the list and shift it over into the sorted list th Keep going until you reach the end of the list "Bubble" to the left until finding the right place
63 Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort First pass through the list SortedUnsorted
Data Structures - CSCI 102 Insertion Sort First pass through the list Swap 64 Copyright © William C. Cheng
65 Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort First pass through the list
66 Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort 2nd pass through the list SortedUnsorted
67 Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort 2nd pass through the list
Data Structures - CSCI 102 Insertion Sort 2nd pass through the list Stay 68 Copyright © William C. Cheng
69 Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort 2nd pass through the list
70 Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort 3rd pass through the list SortedUnsorted
71 Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort 3rd pass through the list
Data Structures - CSCI 102 Insertion Sort 3rd pass through the list Swap 72 Copyright © William C. Cheng
73 Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort 3rd pass through the list
Data Structures - CSCI 102 Insertion Sort 3rd pass through the list Swap 74 Copyright © William C. Cheng
75 Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort 3rd pass through the list
Data Structures - CSCI 102 Insertion Sort 3rd pass through the list Swap 76 Copyright © William C. Cheng
77 Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort 3rd pass through the list
Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort 4th pass through the list SortedUnsorted
Data Structures - CSCI 102 Insertion Sort 4th pass through the list Swap 79 Copyright © William C. Cheng
80 Copyright © William C. Cheng Data Structures - CSCI 102 Insertion Sort 4th pass through the list
Data Structures - CSCI 102 Insertion Sort 4th pass through the list Stay 81 Copyright © William C. Cheng
82 Data Structures - CSCI 102 Insertion Sort 4th pass through the list Too many swaps! Since the left part is sorted, just need to find a place to insert the value (16 in this case) Need to remember the value 16 Copyright © William C. Cheng
In Reverse Order, O(n ) O(n ) 115 Data Structures - CSCI 102 Copyright © William C. Cheng Insertion Sort What’s the best case scenarios? What’s the Big O for this case? Already Sorted, O(n) What’s the worst case scenario? What’s the Big O for this case? 2 What’s the overall Big O? What are the problems with insertion sort? 2 Still have to use nested loops
Divide 4 Data Structures - CSCI 102 Copyright © William C. Cheng Merge Sort Divide the N-element sequence to be sorted into two subsequences of N/2 elements each Conquer Sort the two subsequences recursively using merge sort Combine Merge the two sorted subsequences to produce the a single sorted result. Repeat.
5 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort First pass through the list
6 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort Divide
7 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort
8 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort Divide
9 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort
10 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort Divide
11 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort
12 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort
13 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort Merge
14 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort Merge
15 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort
16 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort Merge
17 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort
18 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort Merge
19 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort
20 Data Structures - CSCI 102 Merge Sort What functions will we need to do merge sort? Need a function to split list in half Need a function to merge two sorted lists Most of the work in the merge sort algorithm is done in the "merge" method Precondition: Given two sorted arrays Postcondition: Need a single, merged sorted array How does it work? Please note that Merge Sort is not an in-place sorting algorithm It uses an output buffer whose size is on the order of the size of the input buffer, i.e., O(n) extra space Merge Sort may not be practical for some applications Copyright © William C. Cheng
21 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist
22 Copyright © William C. Cheng Left Sublist Right Sublist Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Right is smaller Copy right to output
23 Copyright © William C. Cheng Left Sublist Right Sublist Data Structures - CSCI 102 Merge Sort (Merge Algorithm) 3
24 Copyright © William C. Cheng Left Sublist Right Sublist Data Structures - CSCI 102 Merge Sort (Merge Algorithm) 3
25 Copyright © William C. Cheng Left Sublist Right Sublist Data Structures - CSCI 102 Merge Sort (Merge Algorithm) 3 Left is smaller Copy left to output
26 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist 35
27 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist 35
28 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist 35 Left is smaller Copy left to output
29 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist 357
30 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist 357
31 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist 357 Right is smaller Copy right to output
32 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist 3578
33 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist 3578
34 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist 3578 Left is smaller Copy left to output
35 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist
36 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist
37 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist Right is smaller Copy right to output
38 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist
39 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist
40 Copyright © William C. Cheng Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist Right is smaller Copy right to output 16
Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist 41 Copyright © William C. Cheng
Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist Copy all the remaining items from the left sublist to the output 42 Copyright © William C. Cheng
Data Structures - CSCI 102 Merge Sort (Merge Algorithm) Left Sublist Right Sublist Copy all the remaining items from the left sublist to the output Done 43 Copyright © William C. Cheng
What’s the best case scenarios? What’s the Big O for this case? Merge Sort 47 Data Structures - CSCI 102 Copyright © William C. Cheng Merge Sort What’s the worst case scenario? What’s the Big O for this case? What’s the overall Big O? What are the problems with merge sort? None, O(n log n) O(n log n)
Stable Sort (generally) Maintains original ordering of equal elements The Good 48 Data Structures - CSCI 102 Copyright © William C. Cheng Merge Sort Fairly easy to code Useful for lists that must be accessed sequentially e.g. Linked Lists Sorting in place is really difficult The Bad O(N) additional space complexity if not in place There are better in-place sorts Lots of copying data
51 Data Structures - CSCI 102 Copyright © William C. Cheng Quick Sort Pick an element in the array and call it Pivot Divide Split the rest of the array into two subarrays: One array containing all numbers <= Pivot One array containing all numbers > Pivot Sort the two new arrays recursively using quick sort Conquer The arrays are sorted in place. No recombination necessary. Combine We will simply use the last element
52 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort The idea behind the Divide part
Data Structures - CSCI 102 Quick Sort The idea behind the Divide part 1) Choose the last element in the array as the pivot It doesn’t move (until the very end) So, we will pin it where it’s at for now 53 Copyright © William C. Cheng
Data Structures - CSCI 102 Quick Sort The idea behind the Divide part Pivot 1) Choose the last element in the array as the pivot 2) Identify all the numbers smaller than the pivot (in blue) Identify all the numbers larger than the pivot (in orange) 54 Copyright © William C. Cheng
Data Structures - CSCI 102 Quick Sort The idea behind the Divide part Pivot 1) Choose the last element in the array as the pivot 2) Identify all the numbers smaller than the pivot (in blue) Identify all the numbers larger than the pivot (in orange) 3) Move all the numbers smaller than the pivot to the left Move all the numbers larger than the pivot to the right 55 Copyright © William C. Cheng
Data Structures - CSCI 102 Quick Sort The idea behind the Divide part Pivot 1) Choose the last element in the array as the pivot 2) Identify all the numbers smaller than the pivot (in blue) Identify all the numbers larger than the pivot (in orange) 3) Move all the numbers smaller than the pivot to the left Move all the numbers larger than the pivot to the right 4) Move the pivot between the blue and the orange numbers 56 Copyright © William C. Cheng
57 Data Structures - CSCI 102 Quick Sort The idea behind the Divide part final sort order Copyright © William C. Cheng Pivot 1) Choose the last element in the array as the pivot 2) Identify all the numbers smaller than the pivot (in blue) Identify all the numbers larger than the pivot (in orange) 3) Move all the numbers smaller than the pivot to the left Move all the numbers larger than the pivot to the right 4) Move the pivot between the blue and the orange numbers The pivot is now at the correct position in the
58 Data Structures - CSCI 102 Quick Sort The idea behind the Divide part final sort order Copyright © William C. Cheng Pivot QuickSort this 1) Choose the last element in the array as the pivot 2) Identify all the numbers smaller than the pivot (in blue) Identify all the numbers larger than the pivot (in orange) 3) Move all the numbers smaller than the pivot to the left Move all the numbers larger than the pivot to the right 4) Move the pivot between the blue and the orange numbers The pivot is now at the correct position in the
59 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort How to do it?
Data Structures - CSCI 102 Quick Sort How to do it? Pivot Step (1) is easy 60 Copyright © William C. Cheng
Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? PivotUnsorted Keep array split into 3 sections: Numbers less than or equal to the pivot (<= 4, in blue) Numbers greater than the pivot (> 4, in orange) Numbers yet to be sorted 65 Copyright © William C. Cheng
Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? PivotUnsorted Keep array split into 3 sections: Numbers less than or equal to the pivot (<= 4, in blue) Numbers greater than the pivot (> 4, in orange) Numbers yet to be sorted 66 Copyright © William C. Cheng
Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? PivotUnsortedLess Than Pivot Keep array split into 3 sections: Numbers less than or equal to the pivot (<= 4, in blue) Numbers greater than the pivot (> 4, in orange) Numbers yet to be sorted 67 Copyright © William C. Cheng
Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? PivotUnsorted Keep array split into 3 sections: Numbers less than or equal to the pivot (<= 4, in blue) Numbers greater than the pivot (> 4, in orange) Numbers yet to be sorted 68 Copyright © William C. Cheng Less Than Pivot More Than Pivot
Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? PivotUnsorted Keep array split into 3 sections: Numbers less than or equal to the pivot (<= 4, in blue) Numbers greater than the pivot (> 4, in orange) Numbers yet to be sorted 69 Copyright © William C. Cheng Less Than Pivot More Than Pivot
Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? PivotUnsortedLess Than Pivot More Than Pivot Swap 70 Copyright © William C. Cheng
71 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? PivotUnsortedLess Than Pivot More Than Pivot
Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? PivotUnsortedLess Than Pivot More Than Pivot Swap 72 Copyright © William C. Cheng
73 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? PivotUnsortedLess Than Pivot More Than Pivot
74 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? Pivot Unsorted Less Than Pivot More Than Pivot
75 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? PivotLess Than Pivot More Than Pivot
Data Structures - CSCI 102 Quick Sort How to do steps (2) and (3) together? PivotLess Than Pivot More Than Pivot Note: we only swap when the number is < pivot When the number is > pivot, we just move along and did nothing 76 Copyright © William C. Cheng
Data Structures - CSCI 102 Quick Sort Step (4) PivotLess Than Pivot More Than Pivot Swap 77 Copyright © William C. Cheng
78 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort Step (4) PivotLess Than Pivot More Than Pivot
Data Structures - CSCI 102 Quick Sort Step (4) PivotLess Than Pivot More Than Pivot What if some other cell has the same value as the pivot? Does that cell belong to the blue or the orange section? 79 Copyright © William C. Cheng
Data Structures - CSCI 102 Quick Sort Step (4) PivotLess Than Pivot More Than Pivot What if some other cell has the same value as the pivot? Does that cell belong to the blue or the orange section? The answer is: it does not matter if it is done consistently Arbitrarily, we use: blue is for numbers pivot 80 Copyright © William C. Cheng
81 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort Sort Recursively
82 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort Sort Recursively
83 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort Sort Recursively
84 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort Sort Recursively
85 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort Sort Recursively
86 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort Sort Recursively
87 Copyright © William C. Cheng Data Structures - CSCI 102 Quick Sort All done! No merge! Sort Recursively
Sorted or reverse sorted, O(n ) O(n ), but O(n log n) on the average 1) certain inputs can be O(n ) Quick Sort 92 Data Structures - CSCI 102 Copyright © William C. Cheng Quick Sort What’s the best case scenarios? What’s the Big O for this case? What’s the worst case scenario? What’s the Big O for this case? What’s the overall Big O? What are the problems with quick sort? Every partition splits list in half, O(n log n) ) slow on small lists
116 Data Structures - CSCI 102 Copyright © William C. Cheng Extra Material What do sorting algorithms sound like? sorting-algorithms-sound-like/ algorithms/musical_sorting_algorithms.html CSCI 102 YouTube channel Sorting Algorithm Animations