Analgorithmissaidtobeorderfn denotedasofn

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: partitioning
algorithm
 We
will
partition
the
array 
around
the
last
value
(18),
we'll 
call
this
value
the
pivot

 31 12 07 23 93 02 11 18 18 smalls < 18 pivot bigs > 18 John Edgar 58 Partition
this
array
into
small 
and
big
values
using
a 
partitioning
algorithm
 We
will
partition
the
array 
around
the
last
value
(18),
we'll 
call
this
value
the
pivot
 Use
two
indices,
one
at
each 
end
of
the
array,
call
them
low 
and
high
 31 12 07 23 93 02 11 18 arr[low
]
is
greater
than
the
pivot
and 
should
be
on
the
right,
we
need
to 
swap
it
with
something
 John Edgar 59 Partition
this
array
into
small 
and
big
values
using
a 
partitioning
algorithm
 We
will
partition
the
array 
around
the
last
value
(18),
we'll 
call
this
value
the
pivot
 Use
two
indices,
one
at
each 
end
of
the
array,
call
them
low 
and
high
 31 12 07 23 93 02 11 18 arr[low
]
(31)
is
greater
than
the
pivot 
and
should
be
on
the
right,
we
need
to 
swap
it
with
something
 arr[high]
(11)
is
less
than
the
pivot
so 
swap
with
arr[low
]
 John Edgar 60 Partition
this
array
into
small 
and
big
values
using
a 
partitioning
algorithm
 We
will
partition
the
array 
around
the
last
value
(18),
we'll 
call
this
value
the
pivot
 Use
two
indices,
one
at
each 
end
of
the
array,
call
them
low 
and
high
 1 31 12 07 23 93 02 11 18 3 John Edgar 61 Partition
this
array
into
small 
and
big
values
using
a 
partitioning
algorithm
 We
will
partition
the
array 
around
the
last
value
(18),
we'll 
call
this
value
the
pivot
 Use
two
indices,
one
at
each 
end
of
the
array,
call
them
low 
and
high
 11 12 07 23 93 02 31 18 12 02 23 repeat
this
process
until:
 John Edgar 62 Partition
this
array
into
small 
and
big
values
using
a 
partitioning
algorithm
 We
will
partition
the
array 
around
the
last
value
(18),
we'll 
call
this
value
the
pivot
 Use
two
indices,
one
at
each 
end
of
the
array,
call
them
low 
and
high
 11 12 07 02 93 23 31 18 repeat
this
process
until:
 high
and
low
are
the
same
 John Edgar 63 Partition
this
array
into
small 
and
big
values
using
a 
partitioning
algorithm
 We
will
partition
the
array 
around
the
last
value
(18),
we'll 
call
this
value
the
pivot
 Use
two
indices,
one
at
each 
end
of
the
array,
call
them
low 
and
high
 11 12 07 02 93 23 31 18 18 93 repeat
this
process
until:
 high
and
low
are
the
same
 We'd
like
the
pivot
value
to
be
in
the 
centre
of
the
array,
so
we
will
swap
it 
with
the
first
item
greater
than
it
 John Edgar 64 Partition
this
array
into
small 
and
big
values
using
a 
partitioning
algorithm
 We
will
partition
the
array 
around
the
last
value
(18),
we'll 
call
this
value
the
pivot
 Use
two
indices,
one
at
each 
end
of
the
array,
call
them
low 
and
high
 11 12 07 02 18 23 31 93 smalls pivot bigs John Edgar 65 Use
the
same
algorithm
to 
partition
this
array
into
small 
and
big
values
 00 08 07 01 06 02 05 09 00 08 07 01 06 02 05 09 smalls bigs! pivot John Edgar 66 09 08 07 06 05 04 02 01 Or
this
one:
 01 08 07 06 05 04 02 09 smalls pivot bigs John Edgar 67 !  !  The
quicksort
algorithm
works
by
repeatedly
 partitioning
an
array
 Each
time
a
subarray
is
partitioned
there
is
 !  A
sequence
of
small
values,
 !  A
s...
View Full Document

This note was uploaded on 04/17/2010 for the course CMPT 11151 taught by Professor Gregorymori during the Spring '10 term at Simon Fraser.

Ask a homework question - tutors are online