Skip to content

Commit ed5a158

Browse files
committed
Selection sort README file added
1 parent cc18647 commit ed5a158

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Sorting/Selection Sort/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Selection Sort
2+
3+
**Selection sort** is one of the simplest sorting algorithm.
4+
It works by selecting the smallest (or largest, if you want to sort from big to small) element of the array and placing it at the head of the array. Then the process is repeated for the remainder of the array; the next largest element is selected and put into the next slot, and so on down the line.
5+
6+
![Selection Sort](selection_sort.jpg)
7+
8+
Selection sort algorithm starts by compairing first two elements of an array and swapping if necessary, i.e., if you want to sort the elements of array in ascending order and if the first element is greater than second then, you need to swap the elements but, if the first element is smaller than second, leave the elements as it is. Then, again first element and third element are compared and swapped if necessary. This process goes on until first and last element of an array is compared. This completes the first step of selection sort.
9+
10+
If there are n elements to be sorted then, the process mentioned above should be repeated n-1 times to get required result.
11+
12+
#### A visualization on Selection Sort
13+
![Selection sort demonstration](https://upload.wikimedia.org/wikipedia/commons/9/94/Selection-Sort-Animation.gif)
14+
15+
*Selection sort animation. Red is current min. Yellow is sorted list. Blue is current item.*
16+
17+
#### Complexity Analysis
18+
- Worst Case - O(n<sup>2</sup>)
19+
- Average Case - O(n<sup>2</sup>)
20+
- Best Case - O(n<sup>2</sup>)
21+
22+
### More on this topic
23+
- [Selection Sort - WikiPedia](https://en.wikipedia.org/wiki/Selection_sort)
24+
- [Selection Sort - geeksforgeeks](http://quiz.geeksforgeeks.org/selection-sort/)
17.6 KB
Loading

0 commit comments

Comments
 (0)