National Taiwan University of Science and Technology
Algorithm
Fall 2012
9.Medians and order
statistics
Computer Theory Lab.
The ith order statistic of a set of n elemen
t is the ith smallest.
The selection problem can be specified fo
rmally as follows:
Chapter 10
Input: A set of n (distinct) numbers and a nu
mber i, with 1 i
National Taiwan University of Science and Technology
Algorithm
Fall 2012
8.Sorting in linear time
Computer Theory Lab.
8.1 Lower bound for
sorting
The decision tree model
a 1 :a 2
a 2 :a 3
<1,2,3>
a 1 :a 3
Chapter 8
a 1 :a 3
<1,3,2>
<2,1,3>
a 2 :a 3
<3,1,2>
<2,3,1>
<3.2,1>
P.2
Computer Theory Lab.
Chapter 8
P.3
Computer Theory
National Taiwan University of Science and Technology
Algorithm
Fall 2012
2. Getting started
2.1 Insertion sort
Example: Sorting problem
Input: A sequence of n numbers a1 , a2 ,., an
' '
'
a
,
a
,.,
a
Output: A permutation 1 2
n of the
input sequence such that a1 a2 . a.n
The number that we wish to sort are known as
the keys.
National Taiwan University of Science and Technology
Algorithm
Fall 2012
3.Growth of Functions
3.1 Asymptotic notation
( g (n) cfw_ f (n) | c1 , c2 , n0 s.t. 0 c1 g (n) f (n) c2 g (n)
for all n n0
f (n) ( g (n)
g(n) is an asymptotic tight bound for f(n).
`= abuse
2
The definition of required every member
of be asymptotically
National Taiwan University of Science and Technology
Algorithm
Fall 2012
1. The Role of the Algorithms in
Computer
1.1 Algorithms 1/2
Algorithm: Any well-defined computation procedure
that takes some value, or set of values, as input and
produces some value, or set of values, as output.
Or: tool for solving well specific comp
National Taiwan University of Science and Technology
Algorithm
Fall 2012
7.Quicksort
Computer Theory Lab.
7.1 Description of quicksor
t
Divide
Conquer
Combine
Chapter 7
P.2
Computer Theory Lab.
Q U IC K S O R T ( A ,p ,r )
1
if p r
2
th e n
3
Q U IC K S O R T ( A ,p ,q )
4
Q U IC K S O R T ( A ,q + 1 ,r )
Chapter 7
q
P A R T
National Taiwan University of Science and Technology
Algorithm
Fall 2012
6.Heapsort
Computer Theory Lab.
Why sorting
1. Sometimes the need to sort information is
inherent in a application.
2. Algorithms often use sorting as a key
subroutine.
3. There is a wide variety of sorting
algorithms, and they use rich set of
techniques.
National Taiwan University of Science and Technology
Algorithm
Fall 2012
4.Recurrences
Computer Theory Lab.
Recurrences -T ( n ) aT ( n / b ) f ( n )
Substitution method
Recursion-tree method
Master method
Chapter 4
2
Computer Theory Lab.
Technicalities
We neglect certain technical
details when we state and solve
recurrences.