|
|
Merge sort Method :
Definition: Given two sorted arrays, a[p] and b[q], create one sorted array of size p + q of the elements of a[p] and a[q] .
- Assume that we have to keep p+q sorted numbers in an array c[p+q].
- One way of doing this is by copying elements of a[p] and b[q] into c[p+q] and sort c[p+q]which has time complexity of atleast O(n log n).
- Another efficient method is by merging
which is of time complexity of O(n) .
- Method is simple, take one number from each array a and b, place the smallest element in the array c. Take
the next elements and repeat the procedure till all p+q element are placed in the array c.
An Applet Demonstration of Merging
|
|