Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Sorting/bubbleSort.py
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions Sorting/selectionSort.py
Original file line number Diff line number Diff line change
@@ -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]<A[iMin]):
iMin=j
#temp=A[i]
#A[i]=A[iMin]
#A[iMin]=temp
A[i],A[iMin]=A[iMin],A[i]

if __name__=="__main__":

A=[]
print("Enter the elements in array:")
A=list(map(int,input().split(" ")))
#A=[3,7,1,8,0,5]
n=len(A)
print(n,A)
SelectionSort(A,n)
for j in range(0,n):
print(A[j],end=" ")

# Time complexity: O(n^2)
# Space complexity: O(1)