Skip to content

Commit e7b191a

Browse files
authored
Add readme for SelectionSort
1 parent 83d76f5 commit e7b191a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Selection Sort
2+
Selection sort is an algorithm that separates an array into two subsections: a sorted section, and an unsorted section. The array is sorted by moving the lowest value element to the beginning of the unsorted section. It can also be adjusted to sort in reverse order.
3+
```
4+
selection sort(array)
5+
for i <- 0 to indexOfLastElement:
6+
k = i
7+
for j <- i + 1 to indexOfLastElement:
8+
if (array[j] < array[k])
9+
k = j
10+
swap array[k] and array[i]
11+
```
12+
13+
# Time Complexities:
14+
- Worst Case: O(n<sup>2</sup>)
15+
- Best Case: O(n)

0 commit comments

Comments
 (0)