title: Merge Sort in Python - RuntimeError: maximum recursion depth exceeded
body: <p>I am working on merge sort in Python.</p>
  
  <p>I have checked <code>merge</code> function. The arrays are merging fine.</p>
  
  <p>But in the <code>mergeSort</code> Function an error is coming :---</p>
  
  <blockquote>
    <p>RuntimeError: maximum recursion depth exceeded.</p>
    
    <p>RuntimeError                              Traceback (most recent call
    last)  in ()
         63     print(arr[i]),
         64 
    ---> 65 mergeSort(arr,0,n-1)
         66 print(" ")
         67 print("Sorted Array is")</p>
    
    <p> in mergeSort(arr, l, r)
         53         m = l+(r-1)/2
         54         mergeSort(arr,l,m)
    ---> 55         mergeSort(arr,m+1,r)
         56         merge(arr,l,m,r)
         57</p>
  </blockquote>
  
  <p>What can be the possible cause of this?</p>
  
  <pre><code>def merge(arr,l,m,r):
      n1 = m-l+1
      n2 = r-m
  
      L = [0] * n1
      R = [0] * n2
  
      print("First List")
      for i in range(0,n1):
          L[i] = arr[i+l]
          print(L[i]), 
  
  
      print("")
      print("Second List")    
      for j in range(0,n2):
          R[j] = arr[j+m+1]
          print(R[j]),
  
  
  
      #Merging the temp arrays
      i = 0
      j = 0
      k = 0
      print("")
      print("Merged List ----------&gt;")
  
      while i &lt; n1 and j &lt; n2:
          if L[i] &lt;= R[j]:
              arr[k] = L[i]
              print(arr[k]),
              i+=1
          else:
              arr[k] = R[j]
              print(arr[k]),
              j+=1
          k+=1
  
      while i&lt;n1:
          arr[k] = L[i]
          i+=1
          k+=1
  
      while j&lt;n2:
          arr[k] = R[j]
          print(arr[k])
          j+=1
          k+=1
  
  def mergeSort(arr,l,r):
      if l&lt;r:
          m = l+(r-1)/2
          mergeSort(arr,l,m)
          mergeSort(arr,m+1,r)
          merge(arr,l,m,r)
  
  
  arr = [0,12,13,0,1,22]
  n = len(arr)
  
  mergeSort(arr,0,n-1)
  print(" ")
  print("Sorted Array is")
  for i in range(0,n-1):
      print(arr[i])
  </code></pre>