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 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]