Featured
- Get link
- X
- Other Apps
Quick sort in python
Quick sort also use divide and conquer strategy.
In this we find out the correct position for the pivot element and partition the list into two this method is called partition method. Then further seperate the list as same. This method is the backbone of the quick sort.
Using pivot element we going to sort the list. We should follow few condition for quick sort
1) pivot element
2) if start is less than pivot increment
3) if end is greater than pivot increment
[---lesser num--, pivot, --- greater num---]
Number less than pivot should be in left and greater should be in right as above format.
We see more clearly in a example
Algorithm:
Example:
Take list[5, 16, 23, 45, 61, 34, 4]
Take 5 as pivot element
start = list[o]=5
End = list[6]=4
Now start comparing from start and end
i) if start is less than or equal pivot increment
ii) if end is great than pivot increment
iii) when both condition false then swap
-16 is less than pivot, no so stop
-now check end 4 greater than pivot, no so stop
Now both the condition are false so swap (16,4) follow same for other elements as shown in below.
10 > pivot so stop
- Get link
- X
- Other Apps
















Comments
Post a Comment