Selection Sort
π Data Structure and Algorithm
π 76 views
π
Nov 05, 2025
β± Estimated reading time: 1 min
Selection Sort Algorithm
Selection Sort repeatedly selects the smallest element from the unsorted part and places it at the beginning.
Algorithm Steps
- Find the minimum element in the unsorted array.
- Swap it with the first unsorted element.
- Repeat for all elements.
Example (C++)
void selectionSort(int arr[], int n) {
for (int i = 0; i < n-1; i++) {
int minIndex = i;
for (int j = i+1; j < n; j++)
if (arr[j] < arr[minIndex])
minIndex = j;
swap(arr[minIndex], arr[i]);
}
}
Time Complexity
- Best, Average, Worst: O(nΒ²)
Advantages
- Simple and works well on small datasets.
Disadvantages
- Does not adapt to data.
Conclusion
Selection sort is conceptually simple but inefficient for large datasets.
π Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
β Back to Tutorials