Time Complexities of all Sorting Algorithms Last Updated : 19 Mar, 2025 Comments Improve Suggest changes Like Article Like Report The efficiency of an algorithm depends on two parameters:Time ComplexityAuxiliary SpaceBoth are calculated as the function of input size(n). One important thing here is that despite these parameters, the efficiency of an algorithm also depends upon the nature and size of the input. Time Complexity:Time Complexity is defined as order of growth of time taken in terms of input size rather than the total time taken. It is because the total time taken also depends on some external factors like the compiler used, the processor's speed, etc.Auxiliary Space: Auxiliary Space is extra space (apart from input and output) required for an algorithm.Types of Time Complexity :Best Time Complexity: Define the input for which the 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.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.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 ComplexityAuxiliary Space BestAverageWorst WorstSelection SortO(n2)O(n2)O(n2)O(1)Bubble SortO(n)O(n2)O(n2)O(1)Insertion SortO(n)O(n2)O(n2)O(1)Heap SortO(n log(n))O(n log(n))O(n log(n))O(1)Quick SortO(n log(n))O(n log(n))O(n2)O(n)Merge SortO(n log(n))O(n log(n))O(n log(n))O(n)Bucket SortO(n +k)O(n +k)O(n2)O(n)Radix SortO(nk)O(nk)O(nk)O(n + k)Count SortO(n +k)O(n +k)O(n +k)O(k)Shell SortO(n log(n))O(n log(n))O(n2)O(1)Tim SortO(n)O(n log(n))O(n log (n))O(n)Tree SortO(n log(n))O(n log(n))O(n2)O(n)Cube SortO(n)O(n log(n))O(n log(n))O(n)Also, see: Searching and Sorting articlesPrevious year GATE Questions on SortingTime and Space Complexity of Insertion SortTime and Space Complexity of Selection SortTime and Space Complexity of Bubble SortTime and Space Complexity of Quick SortTime and Space Complexity of Merge SortTime and Space complexity of Radix Sort Algorithm Comment More infoAdvertise with us Next Article Time Complexities of all Sorting Algorithms K kartik Follow Improve Article Tags : Analysis of Algorithms Sorting DSA Data Structures and Algorithms-QnA Practice Tags : Sorting Similar Reads Time and Space complexity of Radix Sort Algorithm The Radix Sort Algorithm has a time complexity of O(n*d), where n is the number of elements in the input array and d is the number of digits in the largest number. The space complexity of Radix Sort is O(n + k), where n is the number of elements in the input array and k is the range of the input. Th 2 min read The Slowest Sorting Algorithms A Sorting Algorithm is used to rearrange a given array or list elements according to a comparison operator on the elements. The comparison operator is used to decide the new order of the element in the respective data structure. But Below is some of the slowest sorting algorithms: Stooge Sort: A Sto 15+ min read Classification of Sorting Algorithms Sorting is an algorithm which arranges the elements of a given list in a particular order [ascending or descending]. Sorting algorithms are categorized on the following basis - By number of comparisons :Comparison-based sorting algorithms check the elements of the list by key comparison operation an 3 min read Time and Space Complexity Analysis of Merge Sort The Time Complexity of Merge Sort is O(n log n) in both the average and worst cases. The space complexity of Merge sort is O(n). AspectComplexityTime ComplexityO(n log n)Space ComplexityO(n)Time Complexity Analysis of Merge Sort:Consider the following terminologies: T(k) = time taken to sort k eleme 2 min read Time and Space Complexity Analysis of Bubble Sort The time complexity of Bubble Sort is O(n^2) in the worst-case scenario and the space complexity of Bubble sort is O(1). Bubble Sort only needs a constant amount of additional space during the sorting process. Complexity TypeComplexityTime ComplexityBest: O(n)Average: O(n^2)Worst: O(n^2)Space Comple 3 min read Like