Sorting methods(quick sort,etc)vs Arrays.Sort in speed

Is using Arrays.sort faster than performing some sort sorting operation on an array like bubble sort ,selection sort ,etc ?

2 Likes

Well bubble sort,selection sort takes O(n^2) in worst case. Where as quick sort and merge sort would give you an average of(n logn) although worst case of quick sort may go up to O(n^2). Arrays.sort(in java) is definitely a O(n logn). If you have no idea about the notation which I just used you should just remember that execution time of merge sort or the inbuilt sort Arrays.sort is less in comparison with bubble sort ,selection sort. So while sorting a large input use Arrays.sort .

3 Likes

This link is useful:
stack overflow link

From Java 7, timsort is used with a worst case of O(nlogn), instead of Quick sort which has a worst case of O(n^2).

So, using Arrays.sort is the fastest method possible to sort values in java.

2 Likes

BUT in best case quicksort gives O(n) time complexity…
Is there in JAVA support by built in library to use quickSort?

2 Likes
//