From f7a0b87ad372f982fd42f67f6b6d06cb85b7dbf4 Mon Sep 17 00:00:00 2001 From: 500060783 <500060783@stu.upes.ac.in> Date: Sun, 4 Oct 2020 21:43:29 +0530 Subject: [PATCH 1/2] Selection Sort --- Sorting/selectionSort.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Sorting/selectionSort.py diff --git a/Sorting/selectionSort.py b/Sorting/selectionSort.py new file mode 100644 index 0000000..2bb09b7 --- /dev/null +++ b/Sorting/selectionSort.py @@ -0,0 +1,27 @@ +# Selection Sorting Algorithm + +def SelectionSort(A,n): + for i in range(0,n-1): + iMin=i + for j in range(i+1,n): + if(A[j] Date: Sun, 4 Oct 2020 21:48:49 +0530 Subject: [PATCH 2/2] Bubble Sort --- Sorting/bubbleSort.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Sorting/bubbleSort.py diff --git a/Sorting/bubbleSort.py b/Sorting/bubbleSort.py new file mode 100644 index 0000000..317f951 --- /dev/null +++ b/Sorting/bubbleSort.py @@ -0,0 +1,20 @@ +# Bubble Sorting Algorithm + +def Bubble_Sort(A,n): + for k in range(1,n): + for i in range(0,n-1): + if(A[i]>A[i+1]): + A[i],A[i+1]=A[i+1],A[i] + +if __name__=="__main__": + print("Enter the elements in the array: ") + A=[] + A=list(map(int,input().split(" "))) + n=len(A) + Bubble_Sort(A,n) + print("Sorted Array: ",end="") + for i in range(0,n): + print(A[i],end=" ") + +# Time Complexity: O(n^2) +# Space Complexity: O(1) \ No newline at end of file