I am trying to understand quick search algorithm in pyhton. Here is the code I am working on:
def partition2(a, l, r):
x = a[l]
j = l;
for i in range(l + 1, r + 1):
if a[i] <= x:
j += 1
a[i], a[j] = a[j], a[i]
a[l], a[j] = a[j], a[l]
return j
def randomized_quick_sort(a, l, r):
if l >= r:
return
k = random.randint(l, r)
a[l], a[k] = a[k], a[l]
#use partition3
m = partition2(a, l, r)
randomized_quick_sort(a, l, m - 1);
randomized_quick_sort(a, m + 1, r);
Then I am calling this function defining a variable. For example:
b = [5,1,4]
randomized_quick_sort(b, 0, 2)
MY question is that when I try to print b after the function call, it prints as [1,4,5]. So, how come the value of this array is changing within the function??? It is not a global variable. Whey the local variables inside the function overrides it?? Please help