junaid (quick sort)
TRANSCRIPT
-
8/14/2019 Junaid (Quick Sort)
1/14
By the Name ofBy the Name of
AllahAllah. the most merciful & mighty. the most merciful & mighty
.Presentation No 1.Presentation No 1
Junaid KhanC.No 33
(Morning Shift)
-
8/14/2019 Junaid (Quick Sort)
2/14
Topic :Topic :QUICK SORTQUICK SORT
Quick sort is very Popular sorting
method. C.A.R Hoare introduced it in
1962. It is very important method ofinternal sorting. According to this
algorithm it is faster and easier to sort
two small arrays instead of one largerarray. The quick sort is an algorithm of
Divide-and-conquer. It is also called
Partition exchange sort.
-
8/14/2019 Junaid (Quick Sort)
3/14
Explaining this mechanism with anEx
plaining this mechanism with an
ExampleExam
ple42 31 5 6 7
T
i j
40 30 60 20 10 70 50
Let T be array with 7 elements we will start the
comparison form right to left .we use twopointing variables I and j.
i= Points to 1st location & j= To last location
-
8/14/2019 Junaid (Quick Sort)
4/14
50701020603040
Compare T[j] with T[I] , if T[j] is greater than
T[I] then decrement the j pointerby 1 until
T[j]>T[i].
If at any point T[j]
-
8/14/2019 Junaid (Quick Sort)
5/14
50704020603010T
i i i
If at any point T[i]>T[j] and j>I then swap T[i]
and T[j].
And start from right to left comparison, if
T[j]T[i]).
j
And start comparison from left to right, if T[i]
-
8/14/2019 Junaid (Quick Sort)
6/14
50704020603010
i i i j
50706020403010
i jj
-
8/14/2019 Junaid (Quick Sort)
7/14
50706040203010
i ji
At some point I and j will become equal this
shows that the element of left side of that areless than the middle element and elements at
right side are greater than the element
position I or j.So this is the ourdividing point the elements of
left side are left sub array and the elements on
right side are right sub array.
T
-
8/14/2019 Junaid (Quick Sort)
8/14
Now we will use a stack to postpone the
larger sub problem (sub array) by pushing it
on the top of the stack and continue with the
smaller array and use the same procedure asused above ,after that we will pop the stack
top and start the same procedure with that
sub array and so on.
In this example we have both arrays equal so
we will push right array on the stack top and
proceed with left sub array.
203010T
j ji
-
8/14/2019 Junaid (Quick Sort)
9/14
203010
302010
The left sub array become sorted now
we will sort the right sub array as follow
j
j
i i
i
j
j
T
T
-
8/14/2019 Junaid (Quick Sort)
10/14
706050
607050
507060
T
T
T
5
5
5
6
6
67
7
7
i
i
i j
j
j
i
j
N th i ht b bN th i ht b b
-
8/14/2019 Junaid (Quick Sort)
11/14
Now the right sub array becomeNow the right sub array become
also sorted so we have followingalso sorted so we have following
sorted arraysorted array
70605040302010T
-
8/14/2019 Junaid (Quick Sort)
12/14
You are notKids
Lilo
Any
Question
?
-
8/14/2019 Junaid (Quick Sort)
13/14
MESSAGEMESSAGESuccess is not always
permanent and Failure is notAlways Final, So don't loss
effort until and unless your
.Victory make History
)HITLER(
-
8/14/2019 Junaid (Quick Sort)
14/14
!Have a nice day
Thanks a lot for yourThanks a lot for yoursincere Attentionsincere Attention