What would be complexity? Its all depends how do you merge N arrays of M size!
Complexity of merging:
- Merging two sorted
M size array goes sequentially. So the complexity of this step is O(2M).
N rows
What would be complexity? Its all depends how do you merge N arrays of M size!
Complexity of merging:
- Merging two sorted
M size array goes sequentially. So the complexity of this step is O(2M).
N rows where
each row is sorted and contains
If do it like (Merging linearly ):
- Merging two rows first--you will get intermediate
2M size sorted array.
2M array with another
row of N size matix-- you will get
3M size sorted array.
Merging in this manner
takes N steps and
complexity would be O(N*M).
Better way (divide-and-conquer technique):
Merge all pairs of two consecutive rows first (1,2), (3,4) this give you N/2 pairs of 2M size. in next step merge pairwise. as explain below.
First make pair of two rows and
merge all N/2 pairs first and merge them.
e.g pair row(1,2); row(3,4); row