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

Related Articles

Time Complexities of all Sorting Algorithms

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

The efficiency of an algorithm depends on two parameters:

  1. Time Complexity
  2. Space Complexity

Time Complexity: Time Complexity is defined as the number of times a particular instruction set is executed rather than the total time taken. It is because the total time took also depends on some external factors like the compiler used, processor’s speed, etc.

Space Complexity: Space Complexity is the total memory space required by the program for its execution.

Both are calculated as the function of input size(n).

One important thing here is that in spite of these parameters the efficiency of an algorithm also depends upon the nature and size of the input. 

Types Of Time Complexity :

  1. Best Time Complexity: Define the input for which algorithm takes less time or minimum time. In the best case calculate the lower bound of an algorithm. Example: In the linear search when search data is present at the first location of large data then the best case occurs.
  2. Average Time Complexity: In the average case take all random inputs and calculate the computation time for all inputs.
    And then we divide it by the total number of inputs.
  3. Worst Time Complexity: Define the input for which algorithm takes a long time or maximum time. In the worst calculate the upper bound of an algorithm. Example: In the linear search when search data is present at the last location of large data then the worst case occurs.

Following is a quick revision sheet that you may refer to at the last minute 

 

AlgorithmTime ComplexitySpace Complexity
   BestAverageWorst      Worst
Selection SortΩ(n^2)θ(n^2)O(n^2)O(1)
Bubble SortΩ(n)θ(n^2)O(n^2)O(1)
Insertion SortΩ(n)θ(n^2)O(n^2)O(1)
Heap SortΩ(n log(n))θ(n log(n))O(n log(n))O(1)
Quick SortΩ(n log(n))θ(n log(n))O(n^2)O(n)
Merge SortΩ(n log(n))θ(n log(n))O(n log(n))O(n)
Bucket SortΩ(n +k)θ(n +k)O(n^2)O(n)
Radix SortΩ(nk)θ(nk)O(nk)O(n + k)
Count SortΩ(n +k)θ(n +k)O(n +k)O(k)
Shell SortΩ(n log(n))θ(n log(n))O(n^2)O(1)
Tim SortΩ(n)θ(n log(n))O(n log (n))O(n)
Tree SortΩ(n log(n))θ(n log(n))O(n^2)O(n)
Cube SortΩ(n)θ(n log(n))O(n log(n))O(n)

Also, see:  

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 : 10 Jan, 2023
Like Article
Save Article
Similar Reads
Related Tutorials