# Quick sort problem

I am working on Quick sort algorithm using python . Recently I found a blog on this algorithm which was very easy to understand. I followed excatly the steps that are suggested,but still the program is not working. The idea here is take the pivot element(any random element) and sort the array left to pivot(less than pivot) and right to the pivot(greater than pivot).This is a recursive process .Here is the code.

``````arr = [51,1,21,11,52]

def sort_(arr):
pivot = arr[0]
left = []
right = []
for i in arr:
#print(i>=pivot)
if i >= pivot :
#print(i)
right.append(i)
elif i < pivot:
#r
left.append(i)

#return sort_(left) + [pivot] + sort_(right)
#print(left)

return sort_(left) + [pivot] + sort_(right)

sort_(arr)

``````

Whatâ€™s your base case? That is - when function will stop recursively calling itself?

After sorting both the left part of the array and right part of the array

Okay, but where is that in code?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.