'What is the difference in time and space complexity of passing sub arrays vs indices in merge sort?

Almost every implementation of merge sort online uses indices as arguments like left, mid, right to identify the positions of sub arrays and filling the sub arrays inside the merge method by using those indices to determine the start and ends. I just wanna know if when filling up sub arrays occur in the mergesort method instead of merge method, and passing the left and right sub arrays instead of indices affects performance and what is the exact difference between the two. Sample code:

    public static void MergeMethod(int[] inputArray, int[] leftHalf, int[] rightHalf)
    {
        int leftSize = leftHalf.Length;
        int rightSize = rightHalf.Length;
        int i = 0, j = 0, k = 0;

        while (i < leftSize && j < rightSize)
        {
            if (leftHalf[i] <= rightHalf[j])
                inputArray[k++] = leftHalf[i++];
            else
                inputArray[k++] = rightHalf[j++];
        }

        while (i < leftSize)
            inputArray[k++] = leftHalf[i++];

        while (j < rightSize)
            inputArray[k++] = rightHalf[j++];
    }
        
    public static void SortMethod(int[] inputArray)
    {
        int inputLength = inputArray.Length;

        if (inputLength < 2)
            return;

        int midIndex = inputLength / 2;
        int[] leftHalf = new int[midIndex];
        int[] rightHalf = new int[inputLength - midIndex];

        for (int i = 0; i < midIndex; i++)
            leftHalf[i] = inputArray[i];

        for (int i = midIndex; i < inputLength; i++)
            rightHalf[i - midIndex] = inputArray[i];

        SortMethod(leftHalf);
        SortMethod(rightHalf);
        MergeMethod(inputArray, leftHalf, rightHalf);
    }

as you can see it is a different approact than the common implementations from most sites which is like this https://www.geeksforgeeks.org/merge-sort/. i also tried to differentiate the performance of this implementation vs the common one and this implementation is a lot faster after many trials using large data, im just not sure what is the exact difference and which one is really better.



Solution 1:[1]

In both implementations, the cost T(n) for sorting an array of length n satisfies the recurrence T(n)=2T(n/2)+Theta(n), which has solution T(n)=Theta(n log n). So the asymptotic running time for both implementations is the same, though one implementation could be faster than the other by a constant factor.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ashwin Ganesan