I've been studying about the merge sort algorithm and I can't conclude how many arrays are actually created as part of the algorithm. Certain literature says that the entire original array is copied into a new array that's sorted. But that means only 2 arrays were created.
As far as I understand, the merge sort algorithm has 2 major steps. Splitting and Merging. I thought if you give merge sort an array of 100 slots, it actually creates new arrays as it splits down the middle from 100 > 50/50 > 25/25 > 12/13 > 6/5 > 3/3 > 1/1. After all those splits at this point it has 12 or 13 arrays in memory. And then when finally it copies all these into new arrays from 1 > 2 > 3 or 4 > 6 > 12 > 25 > 50 > 100.
That's another 8 arrays (roughly speaking).
But in text books I read things like this:
You may wonder where all these subarrays are located in memory. In the algorithm, a workspace array of the same size as the original array is created. The subarrays are stored in sections of the workspace array. This means that subarrays in the original array are copied to appropriate places in the workspace array. After each merge, the workspace array is copied back into the original array.
-- Data Structures and Algorithms in Java By Robert Lafore