Skip to content

Commit dcd1418

Browse files
authored
Updated Selection Sort
Two files are having the same name 'Selection sort' due to which people are unable to work on it.
1 parent d733911 commit dcd1418

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Sorts/SelectionSort.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/*
2+
Selection sort is fairly simple. Assume the left part of your array is
3+
sorted and right part is unsorted. Inititally the sorted(left) part is
4+
empty. Now select the smallest element from the unsorted(right) part and
5+
swap it with the first element of the unsorted(right) part. Now this element
6+
is sorted, move to the next iteration and repeat without touch the sorted(left)
7+
part.
8+
*/
9+
110
export default SelectionSort = function (arr) {
211
let n = arr.length;
312

@@ -22,3 +31,5 @@ export default SelectionSort = function (arr) {
2231
}
2332
return arr;
2433
};
34+
35+
// This has the time complexity of O(n^2)

0 commit comments

Comments
 (0)