Time and Space Complexity Analysis of Merge Sort Last Updated : 14 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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 elementsM(k) = time taken to merge k elements So, it can be written T(N) = 2 * T(N/2) + M(N)= 2 * T(N/2) + constant * N These N/2 elements are further divided into two halves. So, T(N) = 2 * [2 * T(N/4) + constant * N/2] + constant * N= 4 * T(N/4) + 2 * N * constant. . .= 2k * T(N/2k) + k * N * constant It can be divided maximum until there is one element left. So, then N/2k = 1. k = log2N T(N) = N * T(1) + N * log2N * constant= N + N * log2N Therefore the time complexity is O(N * log2N). So in the best case, the worst case and the average case the time complexity is the same. Space Complexity Analysis of Merge Sort:Merge sort has a space complexity of O(n). This is because it uses an auxiliary array of size n to merge the sorted halves of the input array. The auxiliary array is used to store the merged result, and the input array is overwritten with the sorted result. Comment More infoAdvertise with us Next Article Time and Space Complexity Analysis of Merge Sort A animeshdey Follow Improve Article Tags : Analysis of Algorithms Sorting DSA Merge Sort Complexity-analysis +1 More Practice Tags : Merge SortSorting Similar Reads Time and Space Complexity Analysis of Quick Sort The time complexity of Quick Sort is O(n log n) on average case, but can become O(n^2) in the worst-case. The space complexity of Quick Sort in the best case is O(log n), while in the worst-case scenario, it becomes O(n) due to unbalanced partitioning causing a skewed recursion tree that requires a 4 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 Time and Space complexity analysis of Selection Sort The Selection sort algorithm has a time complexity of O(n^2) and a space complexity of O(1) since it does not require any additional memory space apart from a temporary variable used for swapping. Time Complexity Analysis of Selection Sort:Best-case: O(n2), best case occurs when the array is already 2 min read Time and Space Complexity of Insertion Sort What is Insertion Sort?Insertion sort is a simple sorting algorithm that works similarly to the way you sort playing cards in your hands. The array is virtually split into a sorted and an unsorted part. Values from the unsorted part are picked and placed in the correct position in the sorted part. T 2 min read 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 Like