1 / 6

Selection Sort

Selection Sort . By Tommy Stevens and Curran (Beast) Trenouth – not struddy. “The Best Kind of Sort there is, what do bubbles have to do with sorting anyways” – Tommy . What is selection sort you ask?.

maylin
Télécharger la présentation

Selection Sort

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Selection Sort By Tommy Stevens and Curran (Beast) Trenouth – not struddy “The Best Kind of Sort there is, what do bubbles have to do with sorting anyways” – Tommy

  2. What is selection sort you ask? • Selection sort is the process of sorting an array of values, i.e a mixed number group from 1-5, in an elegant and efficient way • Don’t believe me? Ask the folks from Algolist.net when they say “Selection sort is notable for its programming simplicity” • Selection sort is one of the O(n2) sorting algorithms, which can make it inefficient for large volumes of date, but when it comes down to small volumes, this is the type of sort you’re looking for

  3. How Does it work? • Selection sort is very simplistic once understood how it works, it is a combination of searching and sorting • Arrays can be thought of as two parts, an unsorted and sorted part. The sorted part is inexistent until the sort has begun, so it can’t be thought of yet. At the beginning, the unsorted part contains the whole array. In every case, the minimal element of the array is sorted and added to the end of the sorted array. Once the unsorted part is empty, that is when your array is completely sorted.

  4. Example Here is a better look at how it works. It will start with the number at position 0. It will check if it’s the smallest #, in this case no, then it will find the smallest #, in this case -5, and it will switch the two numbers, and add -5 to the sorted array. It will repeat this process until the whole array is sorted. In the next case, 1 is the smallest number, so it automatically becomes part of the sorted array, and the next number to be checked is 12, etc.

  5. O(n2) • As we can tell, the number of unsorted elements decreases by one every time a step is conducted. In this case, selection sort makes n steps (number of elements in an array) of loop, before it completely stops. This results in O(n2) [n + (n - 1) + (n - 2) + ... + 1] number of comparisons. • Since selection sort requires n-1 swaps at most, this is why it is very efficient in certain situations

  6. Works cited • http://www.roseindia.net/java/beginners/arrayexamples/SelectionSort.shtml • http://www.algolist.net/Algorithms/Sorting/Selection_sort • http://mathbits.com/mathbits/Java/arrays/SelectionSort.htm

More Related