Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
David Luebke 1 02/10/17
CS 332: Algorithms
Medians and Order Statistics
David Luebke 2 02/10/17
Order Statistics
● The ith order statistic in a set of n elements is
the ith smallest element
● The minimum is thus the 1st order statistic
● The maximum is (duh) the nth order statistic
● The median is the n/2 order statistic
■ If n is even, there are 2 medians
● How can we calculate order statistics?
● What is the running time?
David Luebke 3 02/10/17
Order Statistics
● How many comparisons are needed to find the
minimum element in a set? The maximum?
● Can we find the minimum and maximum with
less than twice the cost?
● Yes:
■ Walk through elements by pairs
○ Compare each element in pair to the other
○ Compare the largest to maximum, smallest to minimum
■ Total cost: 3 comparisons per 2 elements =
O(3n/2)
David Luebke 4 02/10/17
Finding Order Statistics:
The Selection Problem
● A more interesting problem is selection:
finding the ith smallest element of a set
● We will show:
■ A practical randomized algorithm with O(n)
expected running time
■ A cool algorithm of theoretical interest only with
O(n) worst-case running time
David Luebke 5 02/10/17
Randomized Selection
● Key idea: use partition() from quicksort
■ But, only need to examine one subarray
■ This savings shows up in running time: O(n)
● We will again use a slightly different partition
than the book:
q = RandomizedPartition(A, p, r)
≤ A[q] ≥ A[q]
qp r
David Luebke 6 02/10/17
Randomized Selection
RandomizedSelect(A, p, r, i)
if (p == r) then return A[p];
q = RandomizedPartition(A, p, r)
k = q - p + 1;
if (i == k) then return A[q]; // not in book
if (i < k) then
return RandomizedSelect(A, p, q-1, i);
else
return RandomizedSelect(A, q+1, r, i-k);
≤ A[q] ≥ A[q]
k
qp r
David Luebke 7 02/10/17
Randomized Selection
● Analyzing RandomizedSelect()
■ Worst case: partition always 0:n-1
T(n) = T(n-1) + O(n) = ???
= O(n2
) (arithmetic series)
○ 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!
○ What if this had been a 99:1 split?
David Luebke 8 02/10/17
Randomized Selection
● Average case
■ For upper bound, assume ith element always falls
in larger side of partition:
■ Let’s show that T(n) = O(n) by substitution
( ) ( )( ) ( )
( ) ( )∑
∑
−
=
−
=
Θ+≤
Θ+−−≤
1
2/
1
0
2
1,max
1
n
nk
n
k
nkT
n
nknkT
n
nT
What happened here?
David Luebke 9 02/10/17
What happened here?“Split” the recurrence
What happened here?
What happened here?
What happened here?
Randomized Selection
● Assume T(n) ≤ cn for sufficiently large c:
( )
( )
( )
( ) ( )
( ) ( )n
nc
nc
n
nn
nn
n
c
nkk
n
c
nck
n
nkT
n
nT
n
k
n
k
n
nk
n
nk
Θ+





−−−=
Θ+











−−−=
Θ+





−=
Θ+≤
Θ+≤
∑∑
∑
∑
−
=
−
=
−
=
−
=
1
22
1
2
1
22
1
1
2
12
2
2
)(
2
)(
12
1
1
1
1
2/
1
2/
The recurrence we started with
Substitute T(n) ≤ cn for T(k)
Expand arithmetic series
Multiply it out
David Luebke 10 02/10/17
What happened here?Subtract c/2
What happened here?
What happened here?
What happened here?
Randomized Selection
● Assume T(n) ≤ cn for sufficiently large c:
The recurrence so far
Multiply it out
Rearrange the arithmetic
What we set out to prove
( ) ( )
( )
( )
( )
enough)bigiscif(
24
24
24
1
22
1)(
cn
n
ccn
cn
n
ccn
cn
n
ccn
ccn
n
nc
ncnT
≤






Θ−+−=
Θ+−−=
Θ++−−=
Θ+





−−−≤
David Luebke 11 02/10/17
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:
■ Generate a good partitioning element
■ Call this element x
David Luebke 12 02/10/17
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
David Luebke 13 02/10/17
Worst-Case Linear-Time Selection
● (Sketch situation on the board)
● How many of the 5-element medians are ≤ x?
■ At least 1/2 of the medians = n/5 / 2 = n/10
● How many elements are ≤ x?
■ At least 3 n/10  elements
● For large n, 3 n/10  ≥ n/4 (How large?)
● So at least n/4 elements ≤ x
● Similarly: at least n/4 elements ≥ x
David Luebke 14 02/10/17
Worst-Case Linear-Time Selection
● Thus after partitioning around x, step 5 will
call Select() on at most 3n/4 elements
● The recurrence is therefore:
 ( ) ( ) ( )
( ) ( ) ( )
( )( )
enoughbigisif
20
)(2019
)(435
435
435)(
ccn
ncncn
ncn
ncncn
nnTnT
nnTnTnT
≤
Θ−−=
Θ+=
Θ++≤
Θ++≤
Θ++≤
???
???
???
???
???
n/5  ≤ n/5
Substitute T(n) = cn
Combine fractions
Express in desired form
What we set out to prove
David Luebke 15 02/10/17
Worst-Case Linear-Time Selection
● Intuitively:
■ Work at each level is a constant fraction (19/20)
smaller
○ Geometric progression!
■ Thus the O(n) work at the root dominates
David Luebke 16 02/10/17
Linear-Time Median Selection
● Given a “black box” O(n) median algorithm,
what can we do?
■ ith order statistic:
○ Find median x
○ Partition input around x
○ if (i ≤ (n+1)/2) recursively find ith element of first half
○ else find (i - (n+1)/2)th element in second half
○ T(n) = T(n/2) + O(n) = O(n)
■ Can you think of an application to sorting?
David Luebke 17 02/10/17
Linear-Time Median Selection
● Worst-case O(n lg n) quicksort
■ Find median x and partition around it
■ Recursively quicksort two halves
■ T(n) = 2T(n/2) + O(n) = O(n lg n)
David Luebke 18 02/10/17
The End

More Related Content

What's hot

Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
Kumar
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
Quick sort algorithn
Quick sort algorithnQuick sort algorithn
Quick sort algorithn
Kumar
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
Protap Mondal
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
Deepak John
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
Dr Shashikant Athawale
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
District Administration
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
Mohamed Loey
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Merge Sort
Merge SortMerge Sort
Merge Sort
Nikhil Sonkamble
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 
AVL Tree
AVL TreeAVL Tree
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
Jeanie Arnoco
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Dr Shashikant Athawale
 
Recurrences
RecurrencesRecurrences
Recurrences
Ala' Mohammad
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
Tanmay Baranwal
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 

What's hot (20)

Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Quick sort algorithn
Quick sort algorithnQuick sort algorithn
Quick sort algorithn
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
 

Similar to Medians and order statistics

lecture 10
lecture 10lecture 10
lecture 10
sajinsc
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Vikas Sharma
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
pallavidhade2
 
lecture 11
lecture 11lecture 11
lecture 11
sajinsc
 
Quick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And AnalysisQuick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And Analysis
SNJ Chaudhary
 
03 dc
03 dc03 dc
03 dc
Hira Gul
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
Krish_ver2
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
AmayJaiswal4
 
Hash table
Hash tableHash table
Hash table
Rajendran
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
Shiwani Gupta
 
Top school in noida
Top school in noidaTop school in noida
Top school in noida
Edhole.com
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
GadaFarhan
 
presentation_mergesortquicksort_1458716068_193111.ppt
presentation_mergesortquicksort_1458716068_193111.pptpresentation_mergesortquicksort_1458716068_193111.ppt
presentation_mergesortquicksort_1458716068_193111.ppt
ajiths82
 
MergesortQuickSort.ppt
MergesortQuickSort.pptMergesortQuickSort.ppt
MergesortQuickSort.ppt
AliAhmad38278
 
Analysis and design of algorithms part2
Analysis and design of algorithms part2Analysis and design of algorithms part2
Analysis and design of algorithms part2
Deepak John
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
Dr. C.V. Suresh Babu
 
pradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqpradeepbishtLecture13 div conq
pradeepbishtLecture13 div conq
Pradeep Bisht
 
Merge Sort
Merge SortMerge Sort
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sorting
zukun
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
Nv Thejaswini
 

Similar to Medians and order statistics (20)

lecture 10
lecture 10lecture 10
lecture 10
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
lecture 11
lecture 11lecture 11
lecture 11
 
Quick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And AnalysisQuick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And Analysis
 
03 dc
03 dc03 dc
03 dc
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
Hash table
Hash tableHash table
Hash table
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
 
Top school in noida
Top school in noidaTop school in noida
Top school in noida
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
 
presentation_mergesortquicksort_1458716068_193111.ppt
presentation_mergesortquicksort_1458716068_193111.pptpresentation_mergesortquicksort_1458716068_193111.ppt
presentation_mergesortquicksort_1458716068_193111.ppt
 
MergesortQuickSort.ppt
MergesortQuickSort.pptMergesortQuickSort.ppt
MergesortQuickSort.ppt
 
Analysis and design of algorithms part2
Analysis and design of algorithms part2Analysis and design of algorithms part2
Analysis and design of algorithms part2
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
pradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqpradeepbishtLecture13 div conq
pradeepbishtLecture13 div conq
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sorting
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 

More from Rajendran

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
Rajendran
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
Rajendran
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
Rajendran
 
Red black tree
Red black treeRed black tree
Red black tree
Rajendran
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
Rajendran
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Hash tables
Hash tablesHash tables
Hash tables
Rajendran
 
Lower bound
Lower boundLower bound
Lower bound
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
Rajendran
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
Rajendran
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
Rajendran
 
Np completeness
Np completenessNp completeness
Np completeness
Rajendran
 
computer languages
computer languagescomputer languages
computer languages
Rajendran
 
proving non-computability
proving non-computabilityproving non-computability
proving non-computability
Rajendran
 
the halting_problem
the halting_problemthe halting_problem
the halting_problem
Rajendran
 
universality
universalityuniversality
universality
Rajendran
 
mechanizing reasoning
mechanizing reasoningmechanizing reasoning
mechanizing reasoning
Rajendran
 

More from Rajendran (20)

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
 
Red black tree
Red black treeRed black tree
Red black tree
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Hash tables
Hash tablesHash tables
Hash tables
 
Lower bound
Lower boundLower bound
Lower bound
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
 
Np completeness
Np completenessNp completeness
Np completeness
 
computer languages
computer languagescomputer languages
computer languages
 
proving non-computability
proving non-computabilityproving non-computability
proving non-computability
 
the halting_problem
the halting_problemthe halting_problem
the halting_problem
 
universality
universalityuniversality
universality
 
mechanizing reasoning
mechanizing reasoningmechanizing reasoning
mechanizing reasoning
 

Recently uploaded

INTRODUCTION TO MICRO ECONOMICS Dr. R. KURINJI MALAR
INTRODUCTION TO MICRO ECONOMICS Dr. R. KURINJI MALARINTRODUCTION TO MICRO ECONOMICS Dr. R. KURINJI MALAR
INTRODUCTION TO MICRO ECONOMICS Dr. R. KURINJI MALAR
DrRkurinjiMalarkurin
 
Delegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use CasesDelegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use Cases
Celine George
 
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISINGSYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
Dr Vijay Vishwakarma
 
Front Desk Management in the Odoo 17 ERP
Front Desk  Management in the Odoo 17 ERPFront Desk  Management in the Odoo 17 ERP
Front Desk Management in the Odoo 17 ERP
Celine George
 
Debts of gratitude 4meanings announcement format.pptx
Debts of gratitude 4meanings announcement format.pptxDebts of gratitude 4meanings announcement format.pptx
Debts of gratitude 4meanings announcement format.pptx
AncyTEnglish
 
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan ChartSatta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Mohit Tripathi
 
Righteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdfRighteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdf
Zuzana Mészárosová
 
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Neny Isharyanti
 
220711130045_PRIYA_DAS_M.S___Access__ppt
220711130045_PRIYA_DAS_M.S___Access__ppt220711130045_PRIYA_DAS_M.S___Access__ppt
220711130045_PRIYA_DAS_M.S___Access__ppt
Kalna College
 
How to Install Theme in the Odoo 17 ERP
How to  Install Theme in the Odoo 17 ERPHow to  Install Theme in the Odoo 17 ERP
How to Install Theme in the Odoo 17 ERP
Celine George
 
Michael Stevenson EHF Slides June 28th 2024 Shared.pptx
Michael Stevenson EHF Slides June 28th 2024 Shared.pptxMichael Stevenson EHF Slides June 28th 2024 Shared.pptx
Michael Stevenson EHF Slides June 28th 2024 Shared.pptx
EduSkills OECD
 
Haryana Manipur Comparison.pptx
Haryana Manipur Comparison.pptxHaryana Manipur Comparison.pptx
Haryana Manipur Comparison.pptx
Ahmad Asad
 
Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17
Celine George
 
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptxUNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
hemaxiparmar
 
Tales of Two States: A Comparative Study of Language and Literature in Kerala...
Tales of Two States: A Comparative Study of Language and Literature in Kerala...Tales of Two States: A Comparative Study of Language and Literature in Kerala...
Tales of Two States: A Comparative Study of Language and Literature in Kerala...
joshanmath
 
Final ebook Keeping the Memory @live.pdf
Final ebook Keeping the Memory @live.pdfFinal ebook Keeping the Memory @live.pdf
Final ebook Keeping the Memory @live.pdf
Zuzana Mészárosová
 
Capitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptxCapitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptx
CapitolTechU
 
No, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalismNo, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalism
Paul Bradshaw
 
Total and Subtotal in Reports in Odoo 17
Total and Subtotal in Reports in Odoo 17Total and Subtotal in Reports in Odoo 17
Total and Subtotal in Reports in Odoo 17
Celine George
 
NLC English INTERVENTION LESSON 3-D1.pptx
NLC English INTERVENTION LESSON 3-D1.pptxNLC English INTERVENTION LESSON 3-D1.pptx
NLC English INTERVENTION LESSON 3-D1.pptx
Marita Force
 

Recently uploaded (20)

INTRODUCTION TO MICRO ECONOMICS Dr. R. KURINJI MALAR
INTRODUCTION TO MICRO ECONOMICS Dr. R. KURINJI MALARINTRODUCTION TO MICRO ECONOMICS Dr. R. KURINJI MALAR
INTRODUCTION TO MICRO ECONOMICS Dr. R. KURINJI MALAR
 
Delegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use CasesDelegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use Cases
 
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISINGSYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
 
Front Desk Management in the Odoo 17 ERP
Front Desk  Management in the Odoo 17 ERPFront Desk  Management in the Odoo 17 ERP
Front Desk Management in the Odoo 17 ERP
 
Debts of gratitude 4meanings announcement format.pptx
Debts of gratitude 4meanings announcement format.pptxDebts of gratitude 4meanings announcement format.pptx
Debts of gratitude 4meanings announcement format.pptx
 
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan ChartSatta Matka Dpboss Kalyan Matka Results Kalyan Chart
Satta Matka Dpboss Kalyan Matka Results Kalyan Chart
 
Righteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdfRighteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdf
 
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
 
220711130045_PRIYA_DAS_M.S___Access__ppt
220711130045_PRIYA_DAS_M.S___Access__ppt220711130045_PRIYA_DAS_M.S___Access__ppt
220711130045_PRIYA_DAS_M.S___Access__ppt
 
How to Install Theme in the Odoo 17 ERP
How to  Install Theme in the Odoo 17 ERPHow to  Install Theme in the Odoo 17 ERP
How to Install Theme in the Odoo 17 ERP
 
Michael Stevenson EHF Slides June 28th 2024 Shared.pptx
Michael Stevenson EHF Slides June 28th 2024 Shared.pptxMichael Stevenson EHF Slides June 28th 2024 Shared.pptx
Michael Stevenson EHF Slides June 28th 2024 Shared.pptx
 
Haryana Manipur Comparison.pptx
Haryana Manipur Comparison.pptxHaryana Manipur Comparison.pptx
Haryana Manipur Comparison.pptx
 
Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17
 
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptxUNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
 
Tales of Two States: A Comparative Study of Language and Literature in Kerala...
Tales of Two States: A Comparative Study of Language and Literature in Kerala...Tales of Two States: A Comparative Study of Language and Literature in Kerala...
Tales of Two States: A Comparative Study of Language and Literature in Kerala...
 
Final ebook Keeping the Memory @live.pdf
Final ebook Keeping the Memory @live.pdfFinal ebook Keeping the Memory @live.pdf
Final ebook Keeping the Memory @live.pdf
 
Capitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptxCapitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptx
 
No, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalismNo, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalism
 
Total and Subtotal in Reports in Odoo 17
Total and Subtotal in Reports in Odoo 17Total and Subtotal in Reports in Odoo 17
Total and Subtotal in Reports in Odoo 17
 
NLC English INTERVENTION LESSON 3-D1.pptx
NLC English INTERVENTION LESSON 3-D1.pptxNLC English INTERVENTION LESSON 3-D1.pptx
NLC English INTERVENTION LESSON 3-D1.pptx
 

Medians and order statistics

  • 1. David Luebke 1 02/10/17 CS 332: Algorithms Medians and Order Statistics
  • 2. David Luebke 2 02/10/17 Order Statistics ● The ith order statistic in a set of n elements is the ith smallest element ● The minimum is thus the 1st order statistic ● The maximum is (duh) the nth order statistic ● The median is the n/2 order statistic ■ If n is even, there are 2 medians ● How can we calculate order statistics? ● What is the running time?
  • 3. David Luebke 3 02/10/17 Order Statistics ● How many comparisons are needed to find the minimum element in a set? The maximum? ● Can we find the minimum and maximum with less than twice the cost? ● Yes: ■ Walk through elements by pairs ○ Compare each element in pair to the other ○ Compare the largest to maximum, smallest to minimum ■ Total cost: 3 comparisons per 2 elements = O(3n/2)
  • 4. David Luebke 4 02/10/17 Finding Order Statistics: The Selection Problem ● A more interesting problem is selection: finding the ith smallest element of a set ● We will show: ■ A practical randomized algorithm with O(n) expected running time ■ A cool algorithm of theoretical interest only with O(n) worst-case running time
  • 5. David Luebke 5 02/10/17 Randomized Selection ● Key idea: use partition() from quicksort ■ But, only need to examine one subarray ■ This savings shows up in running time: O(n) ● We will again use a slightly different partition than the book: q = RandomizedPartition(A, p, r) ≤ A[q] ≥ A[q] qp r
  • 6. David Luebke 6 02/10/17 Randomized Selection RandomizedSelect(A, p, r, i) if (p == r) then return A[p]; q = RandomizedPartition(A, p, r) k = q - p + 1; if (i == k) then return A[q]; // not in book if (i < k) then return RandomizedSelect(A, p, q-1, i); else return RandomizedSelect(A, q+1, r, i-k); ≤ A[q] ≥ A[q] k qp r
  • 7. David Luebke 7 02/10/17 Randomized Selection ● Analyzing RandomizedSelect() ■ Worst case: partition always 0:n-1 T(n) = T(n-1) + O(n) = ??? = O(n2 ) (arithmetic series) ○ 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! ○ What if this had been a 99:1 split?
  • 8. David Luebke 8 02/10/17 Randomized Selection ● Average case ■ For upper bound, assume ith element always falls in larger side of partition: ■ Let’s show that T(n) = O(n) by substitution ( ) ( )( ) ( ) ( ) ( )∑ ∑ − = − = Θ+≤ Θ+−−≤ 1 2/ 1 0 2 1,max 1 n nk n k nkT n nknkT n nT What happened here?
  • 9. David Luebke 9 02/10/17 What happened here?“Split” the recurrence What happened here? What happened here? What happened here? Randomized Selection ● Assume T(n) ≤ cn for sufficiently large c: ( ) ( ) ( ) ( ) ( ) ( ) ( )n nc nc n nn nn n c nkk n c nck n nkT n nT n k n k n nk n nk Θ+      −−−= Θ+            −−−= Θ+      −= Θ+≤ Θ+≤ ∑∑ ∑ ∑ − = − = − = − = 1 22 1 2 1 22 1 1 2 12 2 2 )( 2 )( 12 1 1 1 1 2/ 1 2/ The recurrence we started with Substitute T(n) ≤ cn for T(k) Expand arithmetic series Multiply it out
  • 10. David Luebke 10 02/10/17 What happened here?Subtract c/2 What happened here? What happened here? What happened here? Randomized Selection ● Assume T(n) ≤ cn for sufficiently large c: The recurrence so far Multiply it out Rearrange the arithmetic What we set out to prove ( ) ( ) ( ) ( ) ( ) enough)bigiscif( 24 24 24 1 22 1)( cn n ccn cn n ccn cn n ccn ccn n nc ncnT ≤       Θ−+−= Θ+−−= Θ++−−= Θ+      −−−≤
  • 11. David Luebke 11 02/10/17 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: ■ Generate a good partitioning element ■ Call this element x
  • 12. David Luebke 12 02/10/17 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
  • 13. David Luebke 13 02/10/17 Worst-Case Linear-Time Selection ● (Sketch situation on the board) ● How many of the 5-element medians are ≤ x? ■ At least 1/2 of the medians = n/5 / 2 = n/10 ● How many elements are ≤ x? ■ At least 3 n/10  elements ● For large n, 3 n/10  ≥ n/4 (How large?) ● So at least n/4 elements ≤ x ● Similarly: at least n/4 elements ≥ x
  • 14. David Luebke 14 02/10/17 Worst-Case Linear-Time Selection ● Thus after partitioning around x, step 5 will call Select() on at most 3n/4 elements ● The recurrence is therefore:  ( ) ( ) ( ) ( ) ( ) ( ) ( )( ) enoughbigisif 20 )(2019 )(435 435 435)( ccn ncncn ncn ncncn nnTnT nnTnTnT ≤ Θ−−= Θ+= Θ++≤ Θ++≤ Θ++≤ ??? ??? ??? ??? ??? n/5  ≤ n/5 Substitute T(n) = cn Combine fractions Express in desired form What we set out to prove
  • 15. David Luebke 15 02/10/17 Worst-Case Linear-Time Selection ● Intuitively: ■ Work at each level is a constant fraction (19/20) smaller ○ Geometric progression! ■ Thus the O(n) work at the root dominates
  • 16. David Luebke 16 02/10/17 Linear-Time Median Selection ● Given a “black box” O(n) median algorithm, what can we do? ■ ith order statistic: ○ Find median x ○ Partition input around x ○ if (i ≤ (n+1)/2) recursively find ith element of first half ○ else find (i - (n+1)/2)th element in second half ○ T(n) = T(n/2) + O(n) = O(n) ■ Can you think of an application to sorting?
  • 17. David Luebke 17 02/10/17 Linear-Time Median Selection ● Worst-case O(n lg n) quicksort ■ Find median x and partition around it ■ Recursively quicksort two halves ■ T(n) = 2T(n/2) + O(n) = O(n lg n)
  • 18. David Luebke 18 02/10/17 The End