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

  1. Find the minimum element in the unsorted array.
  2. Swap it with the first unsorted element.
  3. 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

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes