Question: How to sort k sorted array using mergeSort algorithm? I want to use mergeSort to sort a partially sorted array (k sorted array) but I
How to sort k sorted array using mergeSort algorithm? I want to use mergeSort to sort a partially sorted array (k sorted array) but I am unsure how to do it. My professor says "you dont have to sort the entire array all at once. Instead, you can use the sliding window method where you sort part of the array, then slide the window and sort the next set of elements"
An example of this would be this array: [3, 0, 4, 1, 5, 2, 9, 7, 8, 6], each element is 3 units from where they are supposed to be in the sorted array, k = 3. k is given by the way.
The sorted array: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] where no element moved more than 3 position.
Any advice on how to do this using merge sort only? I know this is simple using insertion or selection but I am required to use merge sort algo only.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
