Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Are you looking for best average time complexity or for what's the fastest to write as code?
-
I think it doesn't take a large time to convert a date to milliseconds. Once its in millis, variation of quicksort heapsort or other fast sorts would suffice
-
Convert to unix timestamp and just .sort
Edit, i think the timestamp is even a class member, but correct me if im wrong -
@StopWastingTime
I think Java should use Timsort in its sort-method.
Its a combination of Insertion-Sort and Mergesort.
It sorts size>=64 with Insertion-sort, else it splits the collection, sort the sub-collections and merges them. -
Average time complexity for what list length? Short lists up to a hundred elements, or long ones with millions?
-
While (!array.isSorted()) {
array.shuffle();
}
But more seriously, it is very rare that you need to do it yourself. Use tools provided by language/framework. They will usually ne netter than your code. Of cause exceptions exist.
For the list less than 1000 items, even bubble sort will be fast enough.
LinQ Order by proved to be good up to 100.000 items in the list (Around 1ms) -
"Hello students! Today we're going to learn about BubbleSort."
"But @Gregozor2121 from the Internet said to never use it!"
"Yeah he's right. Fuck that shit. That's an A+ for you" -
@yellow-dog Oh no! Definitions my only weakness! Is simple if else a sorting algorithm? It sorts! But it isnt scalable! But it sorts! But it is just a simple function!
It depends:
If scalability dosent matter then every sorting algo uses bubble sort.
It it does then it can be solved using a single function that isnt a sorting algo because it isnt scalable. -
@don-rager
That is funny cuz i have heard that from the uni prof...
Some thing about shit performance and only being simple to write that was its only advantage...
Bubble sort shouldnt be used, number of cases where it can be used is small and it always can be replaced by a better one. Most launguages use other sorts in their implemetation anyway so i dont see a point in that discussion.
Or maybe that was a joke that i didnt get...
Related Rants
What is the fastest way to sort an array of dates in java?
question
algorithm
java
array
sort