algo select dalgorithm

8
Linear-Time Selection Deterministic Selection (Algorithm) Design and Analysis of Algorithms I

Upload: navediitr

Post on 03-Dec-2015

216 views

Category:

Documents


0 download

DESCRIPTION

Algo Select Dalogorithm

TRANSCRIPT

Page 1: Algo Select Dalgorithm

Linear-Time SelectionDeterministic Selection (Algorithm)

Design and Analysis of Algorithms I

Page 2: Algo Select Dalgorithm

Tim Roughgarden

The Problem

Page 3: Algo Select Dalgorithm

Tim Roughgarden

Randomized Selection

Page 4: Algo Select Dalgorithm

Tim Roughgarden

Guaranteeing a Good Pivot

Page 5: Algo Select Dalgorithm

Tim Roughgarden

A Deterministic ChoosePivot

Page 6: Algo Select Dalgorithm

Tim Roughgarden

The DSelect AlgorithmDSelect(array A, length n, order statistic i)1. Break A into groups of 5, sort each group2. C = the n/5 “middle elements”3. p = DSelect(C,n/5,n/10) [recursively computes median of C]

4. Partition A around p5. If j = i return p6. If j < i return DSelect(1st part of A, j-1, i)7. [else if j > i] return DSelect(2nd part of A, n-j, i-j)

Page 7: Algo Select Dalgorithm

01

2

3

How many recursive calls does DSelect make?

Page 8: Algo Select Dalgorithm

Tim Roughgarden

Running Time of DSelect