title: recursive call on QuickSort algorithm
body: <p>I have an array as <code>A[] = { 10, 5, 3, 9, 22, 24, 28, 27, 15 }</code>, I wanted to sort this Array using <code>QuickSort</code>. I have a method for quick sort as </p>
  
  <pre><code>QuickSort(int[] num, int start, int end)
  {
     if(start &lt; end)
     {
        int pIndex = Partition(num, start, end); //Pivot Index
        QuickSort(num, start, pIndex-1);
        QuickSort(num, pIndex + 1, end);
     }
  }
  </code></pre>
  
  <p>Here, i am assuming the last index as the pivot element, i.e <code>15</code> is the first pivot element at first iteration.</p>
  
  <p>For Partition:</p>
  
  <pre><code>public static int Partition(int[] arr, int start, int end)
  {
      int pivot = arr[end];
      int i = start - 1;
  
      for (int j = start; j &lt;= end - 1; j++)
      {
          if (arr[j] &lt; pivot)
          {
              i++;
              Swap(arr, i, j);
          }
      }
  
      Swap(arr, i + 1, end);
      return i + 1;
  }
  </code></pre>
  
  <p>As in the <code>QuickSort</code> i divide the problem into two sets, the first with all elements smaller or equal to the pivot, and the second with all elements larger than the pivot.</p>
  
  <p>So, as making the left recursive call I get the output as </p>
  
  <pre><code>3 5 9 10 15 24 28 27 22
  
  3 5 9 10 15 24 28 27 22
  
  3 5 9 10 15 24 28 27 22
  </code></pre>
  
  <p>Now, my confusion is when after sorting the element on the left side, how the recursive call shift to right? </p>
  
  <p>How the <code>pIndex + 1 = 5</code> i.e <code>QuickSort(num, pIndex + 1, end)</code> gets evaluated? </p>
  
  <p>Why after the first right recursive call is made then the program does not evaluate to <code>QuickSort(num, start, pIndex-1)</code>.</p>
  
  <p>Basically, How is recursive call working on the <code>QuickSort</code>?</p>