+ 2

Can you guys tell what type of sorting algorithm is this??

I was learning about sorting algorithms. Then, I coded one in the below a=[1,2,23,32,42,23,1,2,1,1,3,2,5,3,5,3,4,6]#Whatever list you want for i in range(1,len(a)): for j in range(i): if a[i]<a[j]: a[i],a[j]=a[j],a[i] print(a) This is working but I dont know which sorting is this. Please help if you know about sorting in python.

18th Aug 2021, 3:54 PM
Aryan Silswal
3 odpowiedzi
+ 3
The Bubble Sort works similar but some others loops: for i in range(0,len(a)): for j in range(i+1,len(a)):
18th Aug 2021, 4:15 PM
JaScript
JaScript - avatar
+ 3
Thats a variation of Insertion Sort. Recall that in each iteration of insertion sort, the array is sorted up to i-1 and then element i is inserted to its correct position with right shifting elements between. Its just that the shifting of those elements is done with different swaps but still with the same number of swaps.
18th Aug 2021, 4:55 PM
Giorgos
+ 2
Thanks
19th Aug 2021, 4:37 AM
Aryan Silswal