title: QuickSort program reaching maximum recursion limit of 500?
body: <p>I am working on analysis of sorting algorithms by plotting graphs in MATLAB. Below is my quick sort code. When I run it it is giving this error:</p>
  
  <blockquote>
    <p>Maximum recursion limit of <code>500</code> reached. Use <code>set(0,'RecursionLimit', N)</code>
    to change the limit. Be aware that exceeding your available stack space
    can crash MATLAB and/or your computer. Error in ==> quickSort</p>
  </blockquote>
  
  <p>Why does this error occur? Is there anything wrong in my code? </p>
  
  <pre><code>function [ar] = quickSort(ar, low, high)
      if low &lt; high
          [ar, q] = parti(ar, low, high);
          ar = quickSort(ar, low, q - 1);
          ar = quickSort(ar, q + 1, high);
      end
  end
  
  function [ar, i] = parti(ar, p, r)
      x = ar(r);
      i = p - 1;
  
      for j = p : r
          if ar(j) &lt;= x
              i = i + 1;
              if i ~= j
                  tmp = ar(i);
                  ar(i) = ar(j);
                  ar(j) = tmp;
              end
          end
      end
      i = i + 1;
      tmp = ar(i);
      ar(i) = ar(r);
      ar(r) = tmp;
  end
  </code></pre>
  
  <p>I am calling this function using </p>
  
  <pre><code>ar = [7,7,3,0,3,1,4,7,5,6]
  quickSort(ar, 1, 10)
  </code></pre>