Arrays.sort(input) is mentioned as Quick Sort
Closed this issue · 2 comments
Say on FastInterstectionSol2.java class
public void mergeSort(int[] input) {
Arrays.sort(input);
}
but Arrays.sort(input) is a quicksort
Sorts the specified array into ascending numerical order.
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch
as per the documentation.
Yep, you're right, it is quicksort. In previous versions of java it used to be merge sort, infact you can use the legacy merge sort if you use the java runtime args of -Djava.util.Arrays.useLegacyMergeSort=true.
It doesn't really matter if it's a merge sort or quick sort. Both algorithms are on average O(N log N). It is to demonstrate that there exists a faster way to perform an intersection between two list. Maybe the method should be renamed to "fastSort", in case java changes implementation again.
Great !
Thanks for the clarification, "fastSort" is good but simple "sort" to make it simple because fastSort attract developer to dig whats new inside.