CST370 - Week 7
This was our seventh week in CST 370 - Algorithms. Counting Sort Counting Sort is a sorting algorithm that doesn't directly compare elements to sort them. First, we loop through the unsorted array once. During this loop we get the range of values in the array (for example, integers 10-15), we count how many times each number appears, then we calculate their distribution by adding the frequency of each number with the previous. Then, we loop through the unsorted array again, starting from the end. For each number, we place it at the index listed in its distribution value, decrement the distribution value by 1, then continue to the next number. The time efficiency of Counting Sort is O(n + k), where k is the range of values in the input. Counting Sort is also stable, numbers with the same value in the appear in the same order in both the input and output. Radix Sort Radix Sort is another sorting algorithm that doesn't sort by directly comparing numbers. Instead, it runs Count...