Recursion.py help

def f(x):
     if(x==0):
       return     
     else:
       f(x-1)      
       print("this value has been removed from stack 1" ,x)   
       f(x-1)      
       print("this value has been removed from stack 2" ,x)   
f(3)

output–

this value has been removed from stack 1 : 1
this value has been removed from stack 2 : 1
this value has been removed from stack 1 : 2
this value has been removed from stack 1 : 1
this value has been removed from stack 2 : 1
this value has been removed from stack 2 : 2
this value has been removed from stack 1 : 3
this value has been removed from stack 1 : 1
this value has been removed from stack 2 : 1
this value has been removed from stack 1 : 2
this value has been removed from stack 1 : 1
this value has been removed from stack 2 : 1
this value has been removed from stack 2 : 2
this value has been removed from stack 2 : 3

I am trying to implement merge sort algorithm.
In whole merge sort algorithm division of array is done using recursion.

def merge(arr1 , p1 , q1 , r1):
  n1 = q-p+1
  n2 = r-q
  r[n2+1]
  l[n1+1]
  //merging  r and l
def merge_sort(arr , p ,r):
  if(p < r):
    q = floor((p+r)/2)
     merge_sort(arr ,p ,q)
     merge_sort(arr , q+1 , r)
     merge(arr p , q, r)
arr =[5,2,4,1]
merge_sort(arr , 0 , 3)

above multiple recursion is used.
how is it dividing the array using multiple recursion?

I edited your code for the forum. If you do this:

[code]
# code here
[/code]

It will format better. You can also do ``` python ``` using triple backquotes to do the same thing.

Now, it looks like you put a ** on every line, so I’m guessing the whole thing is confusing. I think what you did wrong is you have f(x-1) twice. I also think you might not understand how the stack frame works in python, but I suspect you may be trying to implement some algorithm you’ve read about?

Fill in more information on what you’re trying to do and I’ll see if I can help.