Presentation is loading. Please wait.

Presentation is loading. Please wait.

40 20 10 80 60 50 7 30 100.

Similar presentations


Presentation on theme: "40 20 10 80 60 50 7 30 100."— Presentation transcript:

1 40 20 10 80 60 50 7 30 100

2 Pick Pivot Element Select first element in the array as pivot element
40 20 10 80 60 50 7 30 100

3 40 20 10 80 60 50 7 30 100 [0] [1] [2] [3] [4] [5] [6] [7] [8] s = 0 i
[0] [1] [2] [3] [4] [5] [6] [7] [8] i j

4 While data[i] <= data[pivot] ++i
40 20 10 80 60 50 7 30 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

5 While data[i] <= data[pivot] ++i
40 20 10 80 60 50 7 30 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

6 While data[i] <= data[pivot] ++i
40 20 10 80 60 50 7 30 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

7 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
40 20 10 80 60 50 7 30 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

8 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
40 20 10 80 60 50 7 30 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

9 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] 40 20 10 80 60 50 7 30 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

10 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] 40 20 10 30 60 50 7 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

11 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 60 50 7 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

12 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 60 50 7 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

13 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 60 50 7 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

14 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 60 50 7 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

15 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 60 50 7 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

16 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 60 50 7 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

17 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 7 50 60 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

18 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 7 50 60 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

19 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 7 50 60 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

20 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 7 50 60 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

21 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 7 50 60 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

22 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 7 50 60 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

23 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 7 50 60 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

24 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 7 50 60 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

25 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. 40 20 10 30 7 50 60 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

26 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. Swap data[j] and data[s] 40 20 10 30 7 50 60 80 100 s = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

27 While data[i] <= data[pivot] ++i While data[j] > data[pivot] --j
If i < j swap data[i] and data[j] While j > i, go to 1. Swap data[j] and data[s] 7 20 10 30 40 50 60 80 100 s = 4 [0] [1] [2] [3] [4] [5] [6] [7] [8] i j

28 Partition Result 7 20 10 30 40 50 60 80 100 [0] [1] [2] [3] [4] [5] [6] [7] [8] <= data[pivot] > data[pivot]

29 Recursion: Quicksort Sub-arrays
7 20 10 30 40 50 60 80 100 [0] [1] [2] [3] [4] [5] [6] [7] [8] <= data[pivot] > data[pivot]


Download ppt "40 20 10 80 60 50 7 30 100."

Similar presentations


Ads by Google