Skip to content

Commit 620851c

Browse files
Added the Selection Sort documentation
1 parent 146f173 commit 620851c

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Selection Sort Algorithm
2+
**Selection Sort** is a comparison-based sorting algorithm. It sorts by repeatedly selecting the **smallest (or largest)** element from the unsorted portion and swapping it with the first unsorted element.
3+
1. Find the smallest element and swap it with the first element. This way we get the smallest element at its correct position.
4+
2. Then find the smallest among remaining elements (or second smallest) and swap it with the second element.
5+
3. We keep doing this until we get all elements moved to correct position.
6+
7+
![img.png](img.png)
8+
9+
## Advantages of Selection Sort
10+
- Easy to understand and implement, making it ideal for teaching basic sorting concepts.
11+
- Requires only a constant O(1) extra memory space.
12+
- It requires less number of swaps (or memory writes) compared to many other standard algorithms. Only cycle sort beats it in terms of memory writes. Therefore it can be simple algorithm choice when memory writes are costly.
13+
14+
## Disadvantages of Selection Sort
15+
- Selection sort has a time complexity of **O(n^2)** makes it slower compared to algorithms like Quick Sort or Merge Sort.
16+
- Does not consistently maintain the relative order of equal elements which means it is not stable.
17+
18+
## Complexity Analysis of Selection Sorty
19+
- Time Complexity:
20+
- **O(n^2)**
21+
- Auxiliary Space:
22+
- **O(1)**
23+
24+
## Applications of Selection Sort
25+
- Perfect for teaching fundamental sorting mechanisms and algorithm design.
26+
- Suitable for small lists where the overhead of more complex algorithms isn't justified and memory writing is costly as it requires less memory writes compared to other standard sorting algorithms.
27+
- **Heap Sort** algorithm is based on Selection Sort.
92.3 KB
Loading

0 commit comments

Comments
 (0)