In a typical application using Database, it is natural all...
Read MoreBlog
Sorting Algorithms — Choices
- February 21, 2022
- Posted by: techjediadmin
- Category: Algorithms Data Structures Programming
No Comments
We all know about the standard comparison based sorting algorithms and their time/space complexity. Algorithms like bubble sort, insertion sort, selection sort, quick sort, merge sort, Heap sort operate with a asymptotic lower bound of O(n log n)
. Also, other unconventional sorting algorithms like Bucket Sort, Counting Sort, Radix Sort run in O(n)
We will not talk about implementation details and complexities of these algorithms. Here we will discuss about various situations/requirements you have to deal with and choosing best algorithm for them.
Requirement | Algorithm | Remarks |
---|---|---|
Given array/list is nearly sorted | Insertion sort | Time complexity will be ~O(n) |
Given array has lot of duplicated elements | Counting sort, Bucket sort | Time complexity will be O(n) |
Implement with less write operation (flash devices) | Selection sort | No.of write operation = O(n) |
Data is really huge (Cannot fit in memory) | External Merge sort | Database systems uses these extensively |
Need top K sorted | Modified Heap sort | Time complexity will be ~O(n). Many search engines returning top 10, 20 results |
Sorting Linked list (of big structures) | Merge sort | Database index based sort queries uses them |
In general (with unknown characteristics of input) | Quick sort | – |
Other Sources:
- http://cs.stackexchange.com/questions/3/why-is-quicksort-better-than-other-sorting-algorithms-in-practice
- http://www.sorting-algorithms.com/
- http://en.wikipedia.org/wiki/Sorting_algorithm
- http://www.cprogramming.com/tutorial/computersciencetheory/sortcomp.html
Read Similar Blogs:
Google Authenticator
Google Authenticator is a mobile app that provides two-factor authentication...
Read MoreHow does Serverless Architecture work?
TL;DR: Serverless removes the architecture responsibilities like hardware provisioning, scaling, and...
Read MoreLeave a Reply Cancel reply
Courses
Data Structure & Algorithms for Interviews
Start Date : 24-September-2022
End Date : 27-November-2022
Technology80 Hours10 Weeks
Become a Python Developer
Start Date : 13-August-2022
End Date : 11-September-2022
Technology40 Hours5 Weeks