From bc35ffb8c3f7c2c5d5fddb54a351ea0d5e2611da Mon Sep 17 00:00:00 2001 From: Rakesh Date: Tue, 4 Oct 2022 18:45:34 +0530 Subject: [PATCH] added selection sort --- Python/Sorting-Techniques/selectionSort.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Python/Sorting-Techniques/selectionSort.py diff --git a/Python/Sorting-Techniques/selectionSort.py b/Python/Sorting-Techniques/selectionSort.py new file mode 100644 index 00000000..a82b6d1f --- /dev/null +++ b/Python/Sorting-Techniques/selectionSort.py @@ -0,0 +1,21 @@ +# program for selection sort +#selections sort takes O(n^2) time complexity + + + +#program starts from here +def selectionSort( itemsList ): + n = len( itemsList ) + for i in range( n - 1 ): + minValueIndex = i + + for j in range( i + 1, n ): + if itemsList[j] < itemsList[minValueIndex] : + minValueIndex = j + + if minValueIndex != i : + temp = itemsList[i] + itemsList[i] = itemsList[minValueIndex] + itemsList[minValueIndex] = temp + + return itemsList