why we are always using quick sort ? or any specific sorting algorithm?
An answer to this question on Stack Overflow.
Question
why we are always using quick sort ? or any specific sorting algorithm ??
i tried some experiment on my PC using quick,merge,heap,flash sort
results:-
sorting algorithm : time in nanosecond -> time in minutes
quick sort time : 135057597441 -> 2.25095995735
Flash sort time : 137704213630 -> 2.29507022716667
merge sort time : 138317794813 -> 2.30529658021667
heap sort time : 148662032992 -> 2.47770054986667
using java in built function
long startTime = System.nanoTime();
given times are in nanoseconds there hardly any difference between them if we convert them into seconds for 20000000 random integer data and max array size is 2147483647 in java.if we are using in-place algorithm then there may be difference of 1 to 2 min till max array size.
if the difference is too small why we should care ??
Answer
Correctness. While switching between sort algorithms might offer speed-ups under some specific scenarios, the cost of proving that algorithms work can be quite high.
For instance, TimSort, a popular sorting algorithm used by Android, Java, and Python, had an implementation bug that went unnoticed for years. This bug could cause a crash and was easily induced by the user.
It took a dedicated team "looking for a challenge" to isolate and solve the issue.
For this reason, any time a standard implementation of a data structure or algorithm is available, I will use that standard implementation. The time saved by using a smarter implementation is rarely worth uncertainty about the implementation's security and correctness.