3. What is Merge Sort
Merge Sort is one kind of sorting
that based on Divide and
Conquer algorithm .
3
4. How it works
•
It divides input array in two
halves , calls itself (using
recursive function) for the
two halves and then merges
the two sorted halves .
4
14. Code of Merging Function (part-3)
while(left_index<L_size)
{
a[k]=L[left_index];
left_index++;
k++;
}
while(right_index<L_size)
{
a[k]=R[right_index];
right_index++;
k++;
}
}
14
15. Time Complexity of merge sort
Complexity of merge sort is :
Because At the time of dividing we separate them into two halves .
So the complexity of this part is O(log n) .
Then we merge all the element on increasing or decreasing order. So
in this step the complexity of merging is O(n).
So the overall time complexity of merge sort is O(n * log (n) ).
O(n * log(n))
15
16. Effeciency of Merge Sort
The time complexity of bubble sort , selection sort , insertion sort is
equal to O(n*n).
But the time complexity of merge sort is equal to O(n * log n).
So we need less time for sorting by merge than other sort. So this is
very efficient for computer organization as well as algorithm &
data structure .
16