Assume array A is as follows:
A: Array(1..25):=(13,3,35,86,5,92,30,99,4,36,66,41,27,40,21,20,98,7,10,44,47,37,54,61,72)
Perform a merge sort of A using the following algorithm and using array B(1 .. 25) as extra space.
- Identify 2 increasing sequences: one starting at the left (reading LR) and one starting at the right
(reading RL).
- Merge these 2 sequences into the left of B.
- Repeat step 1 except that the identified sequences start at the element following where the previous sequence stopped.
- Merge the two sequences identifed in step 3 into the RIGHT of B (increasing Right to Left) (ie repeat step 2)
- Repeat steps 1-4, alternating into the left and right of B until steps 1 or 3 meet in the middle
- Repeat (until the list is sorted) steps 1-5, except reverse the roles of A and B (ie next merge sequences from B into A, and then
from A to B again, and so on).
Show the original A and each resulting merged array (ie show A, then B, then A, then B, ...). You will show
about 5 lines (ie ABABA).
For each array that you show, underline the identified sequences that are to be merged into the other array.
- Hint: After step 4 (the first time), B will look like this (merging 13 and 72 into the left and 3, 35, 86 and 61 into the right):
B: Array(1..25):=(13,72, ... 86,61,35,3)