title: Merge Sort Recursion
body: <p>This is a code from Introduction to Java Programming about Merge Sort. This method uses a recursion implementation.</p>
  
  <pre><code>public class MergeSort {
    2    /** The method for sorting the numbers */
    3    public static void mergeSort(int[] list) {
    4      if (list.length &gt; 1) {
    5        // Merge sort the first half
    6        int[] firstHalf = new int[list.length / 2];
    7        System.arraycopy(list, 0, firstHalf, 0, list.length / 2);
    8        mergeSort(firstHalf);
    9  
   10        // Merge sort the second half
   11        int secondHalfLength = list.length - list.length / 2;
   12        int[] secondHalf = new int[secondHalfLength];
   13        System.arraycopy(list, list.length / 2,
   14          secondHalf, 0, secondHalfLength);
   15        mergeSort(secondHalf);
   16  
   17        // Merge firstHalf with secondHalf into list
   18        merge(firstHalf, secondHalf, list);
   19      }
   20    }
  </code></pre>
  
  <p><strong>My question:</strong> is in Line 8 calls the recursion method back to "mergeSort"? If running from the beginning of the method, the "firstHalf" array will be created again and the length will be half short. I think the "firstHalf" can not created again and the length should not be changed if an array is defined already.</p>
  
  <p>Here is the whole code link: <a href="http://www.cs.armstrong.edu/liang/intro9e/html/MergeSortWithLineNumber.html?" rel="nofollow">Merge Sort Java</a>.</p>