+ 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?
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
+ 3
Thanks YUGRAJ ,I also felt the same.
+ 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
+ 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
+ 1
YUGRAJ Yes but for merge sort,heap sort and quick sort
+ 1
There are also some algo that work in n complexity like radix sort, counting sort and bucket sort