Merge Sort - Time Complexity

 Time Complexity of Merge Sort


Algorithm:

 

                MergeSort(left, right){

 

                       If(left < right){

                                   Mid=(left+right)/2

 

                                   MergeSort(left,mid)

                                   MergeSort(mid+1, right)

                                   Merge(left,mid,right)

            }

 

        }






The algorithm shows, MergeSort function devices the entire array into two parts in one iteration. The Programme will terminate when it comes to One element in the array. The following diagram shows how it performs.






The total Number of Executions can be calculated by adding steps that occurred at each level. Therefore the Total number of Executions is equal to n log(n).
So the time complexity is,


                                 F(n) = O (n log(n))

Comments

Popular posts from this blog

Insertion Sort - Time Complexity

Selection Sort - Time Complextity

Redux - Saga