Merge Sort Algorithm: Data Structures
Merge Sort Algorithm: Data Structures
com/)
DATA STRUCTURES
Merge Sort is quite fast, and has a time complexity of O(n log n). It is also a stable sort, which means the "equal" elements are ordered in the same
order in the sorted list.
Like we can see in the above example, merge sort first breaks the unsorted list into sorted sublists, each having one element, because a list of one
element is considered sorted and then it keeps merging these sublists, to finally get the complete sorted list.
while(i <= q)
{
b[k++] = a[i++];
}
while(j <= r)
{
b[k++] = a[j++];
}
Time complexity of Merge Sort is O(n Log n) in all 3 cases (worst, average and best) as merge sort always divides the array in two halves and