You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 620851c
Browse filesBrowse the repository at this point in the historyBrowse files
**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
+

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.
0 commit comments