0 Up votes0 Down votes

0 views19 pagesMedians and Order Statistics

Sep 15, 2017

© © All Rights Reserved

PPT, PDF, TXT or read online from Scribd

Medians and Order Statistics

© All Rights Reserved

0 views

Medians and Order Statistics

© All Rights Reserved

- Cormen 2nd Edition Solutions
- Lesson Plan
- Answer Key Data Structure
- syllabus data structure.doc
- Content for Programming Interviews Exposed, 3rd Edition
- Ans_CH07
- a1_4-cederman
- CDS
- DS Viva Qs
- TMC1433_1434-Assignment02 2014
- IT_SYLLABUS
- Sorting
- Data Structure
- Data Structures
- Quick Sort
- Systolic Design
- Ds Viva Quesans
- Radix Sort 5425
- Howto Sorting
- Asymtote

You are on page 1of 19

CLRS Chapter 9

1

What Are Order Statistics?

The k-th order statistic is the k-th smallest element of an array.

3 4 13 14 23 27 41 54 65 75

n

The lower median is the -th order statistic

2

If n is odd, lower and upper median are the same

3 4 13 14 23 27 41 54 65 75

What are Order Statistics?

Selecting ith-ranked item from a collection.

First: i=1

Last: i=n

n n

Median(s): i = ,

2 2

3

Order Statistics Overview

find ith order stat = A[i]

(n).

I can find max and min in (n) time (obvious)

Can we find any order statistic in linear time? (not

obvious!)

4

Order Statistics Overview

expected-case (n)?

?

?

Pivot, partition, but recur only on one set of data. No join.

5

Using the Pivot Idea

Randomized-Select(A[p..r],i) looking for ith o.s.

if p = r

return A[p]

q <- Randomized-Partition(A,p,r)

k <- q-p+1 the size of the left partition

if i=k then the pivot value is the answer

return A[q]

else if i < k then the answer is in the front

return Randomized-Select(A,p,q-1,i)

else then the answer is in the back half

return Randomized-Select(A,q+1,r,i-k)

6

Randomized Selection

Analyzing RandomizedSelect()

Worst case: partition always 0:n-1

T(n) = T(n-1) + O(n)

= O(n2)

No better than sorting!

Best case: suppose a 9:1 partition

T(n) = T(9n/10) + O(n)

= O(n) (Master Theorem, case 3)

Better than sorting!

Average case: O(n) remember from quicksort

7

Worst-Case Linear-Time Selection

Randomized algorithm works well in practice

What follows is a worst-case linear time algorithm,

really of theoretical interest only

Basic idea:

Guarantee a good partitioning element

Guarantee worst-case linear time selection

Warning: Non-obvious & unintuitive algorithm

ahead!

Blum, Floyd, Pratt, Rivest, Tarjan (1973)

8

Worst-Case Linear-Time Selection

The algorithm in words:

1. Divide n elements into groups of 5

2. Find median of each group (How? How long?)

3. Use Select() recursively to find median x of the n/5 medians

4. Partition the n elements around x. Let k = rank(x)

5. if (i == k) then return x

if (i < k) then use Select() recursively to find ith smallest

element in first partition

else (i > k) use Select() recursively to find (i-k)th smallest

element in last partition

9

Order Statistics: Algorithm

Select(A,n,i): T(n)

Divide input into n/5 groups of size 5. O(n)

All this

/* Partition on median-of-medians */ to find a

medians = array of each groups median. O(n) good split.

pivot = Select(medians, n/5 , n/10 ) T( n/5 )

Left Array L and Right Array G = partition(A, pivot) O(n)

k = |L| + 1 O(1)

If i=k, return pivot O(1)

Only one

If i<k, return Select(L, k-1, i) T(k)

done.

If i>k, return Select(G, n-k, i-k) T(n-k)

10

Order Statistics: Analysis

#less #greater

n

T n T T max k - 1, n - k O(n)

5

How to simplify?

11

Order Statistics: Analysis

Lesser

Elements

Median

Greater

Elements

12

Order Statistics: Analysis

Lesser Median of Greater

Medians Medians Medians

(And at most one smaller group.)

13

Order Statistics: Analysis

Definitely Lesser

Elements

Definitely Greater

Elements

14

Order Statistics: Analysis 1

How many?

15

Order Statistics: Analysis 1

n 5 2 full groups of 5 n 5 2 partial groups of 2

Count elements n n 7n

At most 5 2 2 2 6

outside smaller box.

5 5 10 16

Order Statistics: Analysis

n 7n

T n T T 6 On

5 10

? ?

17

Order Statistics: Analysis

Substitution: Prove Tn c n .

n 7n

T n c c 6 d n

5 10

n 7n

c 1 c 6 d n Overestimate ceiling

5 10

9

c n 7c d n Algebra

10

c n c n 10 7c d n Algebra

c n

when choose c,d such that 0 c n 10 7c d n

18

Order Statistics

Why groups of 5?

? ?

Sum of two recurrence sizes must be < 1.

Grouping by 5 is smallest size that works.

19

- Cormen 2nd Edition SolutionsUploaded byManu Thakur
- Lesson PlanUploaded byknk14091991
- Answer Key Data StructureUploaded byPreba doo
- syllabus data structure.docUploaded bykartheek77723
- Content for Programming Interviews Exposed, 3rd EditionUploaded byzarickzheng
- Ans_CH07Uploaded byPennyLane1812
- a1_4-cedermanUploaded by195380
- CDSUploaded byapi-19908948
- DS Viva QsUploaded bySharma Divya
- TMC1433_1434-Assignment02 2014Uploaded byBang Din
- IT_SYLLABUSUploaded byharij_1
- SortingUploaded byPriyanka Sharma
- Data StructureUploaded byKanimozhi
- Data StructuresUploaded bySarita Sharma
- Quick SortUploaded byalaneed74
- Systolic DesignUploaded byAbhishek Saxena
- Ds Viva QuesansUploaded byGuneet Garg
- Radix Sort 5425Uploaded byMarisa Indah
- Howto SortingUploaded bydalequenosvamos
- AsymtoteUploaded byRam Kumar Basak
- Simple Programming ProblemsUploaded bynikolasmer
- 107352_Lec06b_QuicksortV2Uploaded byvignesvaran
- 5 Searching& SortingsUploaded byVenu Kunchala
- stl_part3Uploaded byMurugappan Sekar
- EfficientParallelMergeSortforFixedandVariableLengthKeysUploaded byrobbiejones96
- ArraysUploaded byGaneshBalaji Katuri
- 72337Uploaded bysathvik
- osfileUploaded byVishal Stark
- Merge SortUploaded byAbhishek Singla
- Bubble SortUploaded byG͎̘̩ͥͪ̓u̩̻̥̭͍̥ͭ͗̋st̩̏͐̓̏ͪ̆ȃ͕͓̫̗̦̥̍̑ͫ͂v͈͖̜̺͉̂̒̇̊͒̚o̫̲̥͎͚̼͙ Ë̖̫̰̲͖́c̲̮̖̉ͥ͆̿̍h̝̲̰͐̾̅̃ͭͥë͂̿v͚̌͛̀̊e͆͌ͥr͓͈̯̮͖̬ͭ̿ͨ͗ͩr̈́ͨ̍ͣy̪̓͗̍̅̽̂ͥ

- CS8451-QBUploaded byThilaga Mylsamy
- parallel processing-GTU paperUploaded bySagar Damani
- tes-2017Uploaded byYohanes Suyanto
- lec6Uploaded bypenguin290
- Sorting AlgorithmsUploaded byfuck
- cs6402-daa-even-qa-qb.pdfUploaded bycoolvadivel
- Ch13Uploaded byCarter Lyon
- DAAUploaded bySrini Vas
- Top 30 Array Interview Questions and Answers for ProgrammersUploaded bySibani Sankar Pradhan
- ch08solUploaded byEric Martin
- DAAUploaded byBhagya Shri
- 2 Marks With AnsUploaded bysubburajs
- Cmpt 125 Study NotesUploaded byMonique Lai
- daaUploaded byVijay Kumar
- OO Case Studies with Patterns and C++Uploaded byImre Tuske
- java programming II Final Exam Study SheetsUploaded bytomritch
- 10.1.1.34Uploaded byluftkissen
- Elementary AlgorithmsUploaded byKonstantine Mushegiani
- Bubble SortUploaded byZarnigar Altaf
- Quick SortUploaded byshower
- ch05.pptUploaded byJeff Torralba
- DAAUploaded bykarthikbabube
- VANIDAALECTURENOTES.pdfUploaded byAbi Haris Hafiz
- 3. Algorithms 2Uploaded byRomeo Balingao
- Sorting Algorithm - Wikipedia, The Free EncyclopediaUploaded bysairam_t
- 10.1.1.230.7114.pdfUploaded bygigi987654
- 11.SortingUploaded bynayle_1990
- TriesUploaded byAnkit Kumar Agarwal
- Ds AssignmentUploaded byAsdf Fdsa
- Introduction to Data StructuresUploaded byArpita Banerjee Bhattacharya

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.