chapter 99.. medians and order statisticsdatamining-iip.fudan.edu.cn/ppts/algo/lecture09.pdf ·...
TRANSCRIPT
Chapter Chapter 99..
Medians and Medians and
Order StatisticsOrder Statistics
Medians and Order Medians and Order StatisticsStatistics
The ith order statistic of a set of n elements is the
ith smallest element. Example: minimum and
maximum
Median: lower median and upper medianMedian: lower median and upper median
Selection problem: selecting the ith order statistic
from a set of n distinct numbers
Selection problem can be solved in O(nlgn)—
faster algorithms?
Average Case- O(n)
Worst case -O(n)
Selection ProblemSelection Problem
Maximum and MinimumMaximum and Minimum
Simultaneously Maximum Simultaneously Maximum and Minimumand Minimum
Selection in Expected Selection in Expected Linear TimeLinear Time
Once position of pivot in A is fixed, it will not changed anymore
AnalysisAnalysis
Worst-case running time: ΘΘ(n2)– We could be extremely unlucky and always recurse on a
sub-array that is only 1 element smaller than the
previous sub-arrayprevious sub-array
Expected running time: O(n)– Randomized-select works well on average
– It is randomized, no particular input bring out the worst-case behavior
The running time of Randomized-select is a random variable T(n), we will obtain an upper bound on E[T(n)]
Expected Running Time(1)Expected Running Time(1)
Including pivot A[q]
With equal probability for all possible k
Expected Running Time(2)Expected Running Time(2)
1
1 / , 1n
k k
i
EX n X
=
= =∑
Expected Running Time(3)Expected Running Time(3)
Expected Running Time(4)Expected Running Time(4)
hypothesis
>0?
Linear Expected Running timeLinear Expected Running time
Selection in worstSelection in worst--case linear timecase linear time
Select algorithm: its running time is O(n) in Select algorithm: its running time is O(n) in
the the worst caseworst case
It finds the desired element by recursively It finds the desired element by recursively
partitioning the input arraypartitioning the input arraypartitioning the input arraypartitioning the input array
The The main ideamain idea behind the algorithm, behind the algorithm,
however, is to however, is to guaranteeguarantee a a good splitgood split
Select use deterministic PARTITION Select use deterministic PARTITION
algorithm with algorithm with pivotpivot as inputas input
SELECT (1)SELECT (1)
Median of median
SELECT (2)SELECT (2)
Analysis (1)Analysis (1)
Analysis (2): #nodes greater Analysis (2): #nodes greater than xthan x
Both elements greater
than and less than x are
all at least 3n/10-6
Analysis (3)Analysis (3)
No matter recursively call on which sides of x, at most 7n/10+6 elements
RecurrenceRecurrence
Constants 140?Constants 140?
ConclusionConclusion
Class ExerciseClass Exercise
Exercise 9.1Exercise 9.1--2, 9.22, 9.2--2, 9.32, 9.3--55