Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Know Your Sorting Algorithm | Set 1 (Sorting Weapons used by Programming Languages)

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Ever wondered how sort() function we use in C++/Java or sorted() in Python work internally? Here is a list of all the inbuilt sorting algorithms of different programming languages and the algorithm they use internally.

  1. C’s qsort() – Quicksort
    • Best Case Time Complexity- O(NlogN)
    • Average Case Time Complexity- O(NlogN)
    • Worse Case Time Complexity- O(N2)
    • Auxiliary Space- O(log N)
    • Stable- Depends on the implementation of the comparator function
    • Adaptive- No
  2. C++’s sort() – Introsort (Hybrid of Quicksort, Heap Sort and Insertion Sort
    • Best Case Time Complexity- O(NlogN)
    • Average Case Time Complexity- O(NlogN)
    • Worse Case Time Complexity- O(NlogN)
    • Auxiliary Space- O(logN)
    • Stable- No
    • Adaptive- No
  3. C++’s stable_sort() – Mergesort
    • Best Case Time Complexity- O(NlogN)
    • Average Case Time Complexity- O(NlogN)
    • Worse Case Time Complexity- O(NlogN)
    • Auxiliary Space- O(N)
    • Stable- Yes
    • Adaptive- Yes
  4. Java 6’s Arrays.sort() – Quicksort
    • Best Case Time Complexity- O(NlogN)
    • Average Case Time Complexity- O(NlogN)
    • Worse Case Time Complexity- O(N2)
    • Auxiliary Space- O(logN)
    • Stable- Depends
    • Adaptive- No
  5. Java 7’s Arrays.sort() – Timsort (Hybrid of Mergesort and Insertion Sort)
    • Best Case Time Complexity- O(N)
    • Average Case Time Complexity- O(NlogN)
    • Worse Case Time Complexity- O(NlogN)
    • Auxiliary Space- O(N)
    • Stable- Yes
    • Adaptive- Yes
  6. Java’s Collections.sort() – Mergesort
    • Best Case Time Complexity- O(NlogN)
    • Average Case Time Complexity- O(NlogN)
    • Worse Case Time Complexity- O(NlogN)
    • Auxiliary Space- O(N)
    • Stable- Yes
    • Adaptive- Yes
  7. Python’s sorted() – Timsort (Hybrid of Mergesort and Insertion Sort)
    • Best Case Time Complexity- O(N)
    • Average Case Time Complexity- O(NlogN)
    • Worse Case Time Complexity- O(NlogN)
    • Auxiliary Space- O(N)
    • Stable- Yes
    • Adaptive- Yes
  8. Python’s sort() – Timsort (Hybrid of Mergesort and Insertion Sort)
    • Best Case Time Complexity- O(N)
    • Average Case Time Complexity- O(NlogN)
    • Worse Case Time Complexity- O(NlogN)
    • Auxiliary Space- O(N)
    • Stable- Yes
    • Adaptive- Yes
  9. C# sort() – Introsort or introspective sort (Hybrid of Quicksort, Heap Sort and Insertion Sort
    • Best Case Time Complexity- O(NlogN)
    • Average Case Time Complexity- O(NlogN)
    • Worse Case Time Complexity- O(NlogN)
    • Stable – Depends

In the next sets we will implement Introsort ( C++’s sorting weapon ) and Sleep sort, Gnome Sort and other unconventional sorting algorithms. This article is contributed by Rachit Belwariar. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above

My Personal Notes arrow_drop_up
Last Updated : 13 May, 2022
Like Article
Save Article
Similar Reads
Related Tutorials