Selection Sort
📘 Data Structure and Algorithm
👁 210 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