1. Problem Definition:
Input: array A with n distinct numbers and each number i is in {1, 2, 3, ... , n}
Output: ith smallest element in A
2. Randomized Selection:
RSelect(array A , length n, order statistic i )
a) if n = 1 return A[1]
b) choose pivot p from A uniformly at random
c) partition A around p , let j = new index of p
d) if j = i , return p
e) if j > i , return R ( 1st part of A, j -1 , i )
f) if j < i , return R( 2nd part of A, n - j , i - j )
3. Running Time of RSelect depends on which pivots get chosen. ( could be as bad as O(n^2) )
Best pivot is the median ( but choosing the media needs RSelect...)
For the best case : T(n) <= T(n/2) + O (n) , per Master Method, T(n) = O(n)
4. RSelect Theorem : for every input array of length n , the average running time of RSelect is O(n).
-- it holds for every input (no assumption on data)
-- "average" is over random pivot choices made by the algorithm
5. Tracking progress via phases :
RSelect is in Phase j if current array size between (3/4) ^(j+1) n and (3/4)^j n
Let random variable Xj = the number of recursive calls during phase j
So running time of RSelect <= Sum(phase j ) {Xj * c * (3/4)^j * n }
6. If RSelect choose a pivot giving a 25-75 split (or better) then current phase ends.
The probability of 25-75 split or better is 50%
E[Xj] <= expected number of times you need to flip a fair coin to get one "head"(head <==> good pivot)
Let N = number of coin flips until you get head.
E[ N] = 1/2 * 1 + 1/2 ( 1 + E[N] )
probability of head probability of tail # of further coin flips
E[N] = 2 , so E[Xj] <= E[N] = 2
7. Running time of RSelect <= Sum(phase j) {Xj * c * (3/4)^j * n }
<= 2* c*n*Sum(phase j) { (3/4)^j}
<= 2* c*n* 1/(1-3/4) = 8cn = O(n)
8. Deterministic Linear-Time Selection:
Goal: find pivot guaranteed to be pretty good.
key idea: use "median of medians"
9. Deterministic ChoosePivot(A,n) :
a) logically break A into n/5 groups of size 5 each
b) sort each group (e.g. using inertion sort)
c) copy n/5 medians into new array C
d) recursively compute median of C
e) return the median of C as pivot.
10. DSelect(array A, length n, order statistic i)
a) Break A into groups of size 5, sort each group
b) C = the n/5 “middle elements”
c) p = DSelect(C,n/5,n/10) [recursively computes median of C]
d) Partition A around p , j = new index of p
e) If j = i return p
f) If j > i return DSelect(1st part of A, j-1, i)
g) [else if j < i] return DSelect(2nd part of A, n-j, i-j)
11. DSelect Theorem:
For every input array of length n, DSelect runs in O(n) time
It's not as good as RSelect in practice due to :
a) worse constant factors
b) not in place
12. Soring an array of 5 elements takes constant time, So the 1st step of DSelect takes O(n)
13. Let k = n/5 = # of groups
Let x(i) = ith smallest of the k "middle elements".
So the pivot = x(k/2).
So there are at least n/2 * 3/5 elements smaller than pivot and at least n/2 * 3/5 elements bigger than pivot.
So the second recursive call of DSelect guaranteed to be on an array of size <= 7/10 n
14. Let T(n) = maximum running time of DSelect on an input array of length n.
There is a constant c >= 1 such that :
a) T(1) = 1
b) T(n) <= cn + T(n/5) + T(7/10 n)
Inductive proof for T(n) = O(n) :
Suppose T(n) <= an , a is a constant (for all size < n)
T(n) <= cn + a (n/5) + a (7/10 n) = (c + 9/10 a) n
To let (c + 9/10 a) n <= an , 10c <= a, let a = 10c , then for all n, T(n) <= an
相关推荐
在给定的"Linear-time-selection.zip"压缩包中,包含了一个名为"2.cpp"的文件,这很可能是一个用Visual C++实现的线性时间选择算法的示例。 线性时间选择算法的起源可以追溯到1975年Rony Hoare提出的“快速选择”...
线性时间选择 实现了 Blum、Floyd、Pratt、Rivest 和 Tarjan 描述的选择算法。 它以O(n)时间复杂度运行,在排序数组的情况下最好的情况是 O(1)。 实现作为包含在包io.gitbub.thehappybug.Algorithms中的...
1.2.2 Time-Dispersive vs. Frequency-Dispersive Fading 16 1.2.3 Statistical Characterization and Generation of Fading Channel 19 2 SISO Channel Models 25 2.1 Indoor Channel Models 25 2.1.1 General ...
Understanding and Inductive Inference.- Computing with Cells: Membrane Systems.- Complexity and Inapproximability.- Boxicity and Poset Dimension.- On the Hardness against Constant-Depth Linear-...
在选择设备时,用户需要点击 Rotation---Rotation,选择双击Reduct.gear,然后在 Rotation--Linear 栏目选择双击H ballscrew,最后在Linear--Linear 栏目选择双击H linear。这三个设备是伺服电机选型的关键组件。 ...
We cover the topics of feature selection and reduction, linear modeling, logistic models, non-linear models, SVM and kernels, ensemble learning techniques such as bagging and boosting, validation ...
- Non-linear analysis (3rd order statistics) - Test for UnitCircle- and Hurwitz- Polynomials - multiple signal processing - Several criteria (AIC, BIC, FPE, MDL, SBC, CAT, PHI) for model order ...
2.3 A FSF Architecture Using Adaptive Linear Combiner Filter and Radial Basis Function Network Feature Extractor 2.3.1 FSF Realization 2.3.2 ALC-RBF FSF System Learning 2.3.3 Image Contour ...
9.2 Selection in expected linear time 215 9.3 Selection in worst-case linear time 220 III Data Structures Introduction 229 10 Elementary Data Structures 232 10.1 Stacks and queues 232 10.2 Linked ...
9.2 Selection in expected linear time 185 9.3 Selection in worst-case linear time 189 III Data Structures Introduction 197 10 Elementary Data Structures 200 l0.l Stacks and queues 200 l0.2 Linked ...
4.3 Architecture Selection. 4.4 System Implementation. 4.5 Designing for Tuning and Debugging. 5 Mapping Techniques. 5.1 Timing Constraints. 5.2 Memory Bandwidth Constraints. 5.3 Resource Constraints....
- The exercise introduces the SELECTION-SORT algorithm, which sorts an array by repeatedly finding the minimum element from the unsorted part and putting it at the beginning. These specific exercises...
c DATIME(DATETM), RETURNS AN 80 CHARACTER STRING WITH CURRENT DATE AND TIME. CAN C BE A DUMMY ROUTINE IF SYSTEM PROGRAMMING IS TOO MUCH. C INPUTD(FILENAME), TAKES THE NAMED FILE AND USES IT TO GET ...
Later chapters present an extensive coverage on Self Organizing Maps for nonlinear data clustering, recurrent networks for linear nonlinear time series forecasting, and other network types suitable ...
A 2 minute timeout has been added to the collection of system information. - Video playback, Hard disk and CD/DVD test 'no operations' error reporting changed. - When BurnInTest crashes, it will ...