how does the sort inbuilt function work internally and when we add comaparator function as third arguement in sort function , how does it work again internally.
Comparator function in sort inbuilt function
Algorithms used by sort()
The algorithm used by sort() is IntroSort. Introsort being a hybrid sorting algorithm uses three sorting algorithm to minimise the running time, Quicksort, Heapsort and Insertion Sort. Simply putting, it is the best sorting algorithm around. It is a hybrid sorting algorithm, which means that it uses more than one sorting algorithms as a routine.
When you use comparator function , it just ordered the selected elements according to the given comparator function. So, basically comparator function is nothing just giving a external functionality to sort function .
Hit like if u get it
1 Like
Anubhav sir can you please explain IntroSort little more, using a complete example, and do a dry run on it please.
Thank you