SwadhyAI Notes

All Python notes

Selection Sort in Python 🔍

Find Minimum and Swap

Selection sort repeatedly finds the minimum element from the unsorted part and puts it at the beginning.

💻 Implementation

python
def selection_sort(arr):
    for i in range(len(arr)):
        min_idx = i
        for j in range(i+1, len(arr)):
            if arr[j] < arr[min_idx]:
                min_idx = j
        arr[i], arr[min_idx] = arr[min_idx], arr[i]

arr = [64, 25, 12, 22, 11]
selection_sort(arr)
print(arr)

🎮 Interactive Selection Sort Demo

Speed:
ℹ️ Ready
Comparing/Active
Sorted

⚠️ Performance

Time Complexity: O(n²). Not suitable for large datasets.