18/9/2007 I2A 98 slides 6
1
Richard Bornat Dept of Computer Science
( ) time in the worst case, but it is Quicksort takes O N 2 easy to - - PDF document
Quicksort : the best of sorts? Weiss calls this the fastest-known sorting algorithm. ( ) time in the worst case, but it is Quicksort takes O N 2 easy to make it use time proportional to N lg N in almost every case. It is claimed to be
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
.. !1:
.. !1 and Ai n .. !1,
.. !1 is (#) each number in Ai n .. !1, but not
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
.. !1 into two approximately equal halves:
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
untreated m,i n,j
i #
!1, we expand the areas within which
untreated m n i j #p p<
!
i j 1 - i.e. p
i j
!1
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
+
( )÷2 –
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
.. !1
.. !1 is smaller than the input Am n .. !1: that is, we
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
.. !1. Then re-
.. !1, which contains values (#p); Ak k
n + ! 1 1 ..
m n k #p p< k+1 p
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
n + ! 1 1 ..
m n i,j #p p< m+1 p
i + ! 1 1 ..
.. !1might be empty
m n i-1 #p p< i,j p
.. !2, call it again on Ai n .. !1,
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
m n i <p p< m+1 p j untreated
i j
!1
m n i #p p# m+1 p j untreated
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
i j
!1. From the second we deduce that
i j
!1 and therefore i
i j
!1 and we can’t deduce that
i j
!1; although i
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
m n i,j #p p# m+1 p
m n j #p p# m+1 p i =p
.. !2 and Ai n .. !1.
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
i <
!1, because the sentinel in Am+1 will
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
m+ # 1
!1 is true to begin with, and each time we
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
r
!
s
1
i! # 1
+
r
j "
+
s
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
2
2
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 6
Richard Bornat Dept of Computer Science