What is the difference between my default way of sorting and bubble sorting of a list? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What is the difference between my default way of sorting and bubble sorting of a list?

I recently learned bubble sorting.Well, the sorting style is kind of different than my way of sorting but the loops continues same time in both sorting in same list. Here is an example: https://code.sololearn.com/ca3a18a12A16 https://code.sololearn.com/c5a3a0A12a22 More information about bubble sort: https://www.geeksforgeeks.org/bubble-sort/ So now I am guessing that the way of two sorting are same but I cannot figure it how.So my question is ,is these two sorting way are really same or different and if they are same then how? Is my way of sorting is also a bubble sorting?

23rd Apr 2021, 4:45 PM
The future is now thanks to science
The future is now thanks to science - avatar
6 Answers
+ 3
Second code is just optimised version of first one by running second loop lesser if you know exactly how bubble sort works then you can explain how second code is running properly. But both are bubble sort
23rd Apr 2021, 5:05 PM
YUGRAJ
+ 3
Thanks YUGRAJ ,I also felt the same.
23rd Apr 2021, 5:35 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
The thing is the time complexity bubble sort, selection sort are the not the most optimised way for sorting. It takes O(log n)² for it on the other hand other other algorithms. For example-Insertion sort it's time complexity for bigger elements is O(log n)² but it works smoothly for smaller elements. This stuffs are noticed when you will handle big projects
24th Apr 2021, 5:04 PM
Atul [Inactive]
+ 2
Atul they work in n² not logn² and there are more faster algorithm than these three that can work in nlogn leke quick sort, heap sort, merge sort
24th Apr 2021, 5:08 PM
YUGRAJ
+ 1
YUGRAJ Yes but for merge sort,heap sort and quick sort
24th Apr 2021, 5:10 PM
Atul [Inactive]
+ 1
There are also some algo that work in n complexity like radix sort, counting sort and bucket sort
24th Apr 2021, 5:11 PM
YUGRAJ