Merge Sort function using Multithreading.
Merge Sort is a divide and conquer technique.
MergeSort algorithm takes three steps:
Divide step computes mid position of sub-array and it takes constant time O(1).
Conquer step recursively sort two sub arrays of approx n/2 elements each.
Combine step merges a total of n elements at each pass requiring at most n comparisons so it take O(n).
Merge Sort is an efficient, stable sorting algorithm with an average, best-case, and worst-case time complexity of O(n log n)
.
Multiple threads are created during Merge Sort. In this code we have made 4 threads.
We can enhance the performance of merge sort using the multithreading.