SlideShare a Scribd company logo
Medians and Order
Statistics
Order statistics
ith order statistic is the ith smallest element of a set of n elements.
We will consider some special cases of the order statistics :
The minimum, i.e. the first(i=1),
the maximum, i.e. the last(i=n),
and the median, i.e. the “halfway point."
If n is odd, the median is unique, and if n is even, there are two
medians(lower median and upper median).
Selection problem
It is a problem of computing where
Input: A set A of n distinct numbers and a number i, with 1 i  n.
Output: the element x  A that is larger than exactly i – 1 other elements of A.
Naïve Solution
We can simply sort the given numbers using heap or merge sort and then
simply giving the output as ith index of the array.
If we use a sorting algorithm then the selection problem can be solved in in
O(n lg n) time.
But using a sorting is more like using a cannon to shoot a fly since only one
number needs to computed.
So we will just find out that number. Before that let us solve the problem of
selecting the minimum and maximum of a given set of number.
Minimum and Maximum
Minimum (A)
1. min = A[1]
2. for i = 2 to A.length
3. if min > A[i]
4. Min = A[i]
5. return min
Maximum can be determined similarly.
How many comparisons are necessary and
sufficient for computing both the minimum
and the maximum?
Well, to compute the minimum n-1 comparisons are necessary and
sufficient. The same is true for the maximum. So, the number should be
2n-2 for computing both.
Is it possible to find out the minimum and maximum in less than 2n-2
comparisons?
YES , lets see how…..
Simultaneous Minimum and Maximum
Simultaneous computation of maximum and minimum can be done in at
most 3n/2 steps.
Idea: Maintain the variables min and max. Process the n numbers in pairs.
For the first pair, set min to the smaller and max to the other. After that, for
each new pair, compare the smaller with min and the larger with max.
Lets see the algorithm.
MAX-AND-MIN(A , n)
1. max = A[n], min = A[n]
2. for i = 1 to n/2
3. if A[2i - 1] ≥ A[2i]
4. { if A[2i - 1] > max
5. max = A[2i - 1]
6. if A[2i] < min
7. min = A[2i] }
8. else { if A[2i] > max
9. max = A[2i]
10. if A[2i - 1] < min
11. min A[2i - 1] }
12. return max and min
Randomized-Select
Randomized-Select (A, p, r, i)
1. if p = r
2. return A[p]
3. q = Randomized-Partition(A, p, r)
4. k =q – p + 1
5. if i = k
6. return A[q]
7. else if i < k
8. return Randomized-Select(A, p, q – 1, i)
9. else return Randomized-Select(A, q+1, r, i – k)
…
Randomized-Partition(A, p, r)
1. i = random(p,r)
2. exchange A[r] with A[i]
3. return Partition(A, p, r)
Partition(A, p, r)
1. x=A[r]
2. i=p-1
3. for j=p to r-1
4. if A[j]≤x
5. i=i+1
6. exchange A[i] with a[j]
7. exchange A[i+1] with A[r]
8. return i+1
Example
6 10 13 5 8 3 2 11
i=7
Analysis
…
…
…
…
…
Thank You !

More Related Content

What's hot

lecture 10
lecture 10lecture 10
lecture 10
sajinsc
 
Project business maths
Project business mathsProject business maths
Project business maths
areea
 
Introduction to Matrices
Introduction to MatricesIntroduction to Matrices
Introduction to Matrices
holmsted
 
presentation on matrix
 presentation on matrix presentation on matrix
presentation on matrix
Nikhi Jain
 
MATRICES
MATRICESMATRICES
MATRICES
daferro
 

What's hot (19)

Introduction to matices
Introduction to maticesIntroduction to matices
Introduction to matices
 
Introduction of matrix
Introduction of matrixIntroduction of matrix
Introduction of matrix
 
lecture 10
lecture 10lecture 10
lecture 10
 
Matrix presentation By DHEERAJ KATARIA
Matrix presentation By DHEERAJ KATARIAMatrix presentation By DHEERAJ KATARIA
Matrix presentation By DHEERAJ KATARIA
 
M a t r i k s
M a t r i k sM a t r i k s
M a t r i k s
 
Project business maths
Project business mathsProject business maths
Project business maths
 
Matrices
MatricesMatrices
Matrices
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Lesson 1 matrix
Lesson 1 matrixLesson 1 matrix
Lesson 1 matrix
 
Matrices
MatricesMatrices
Matrices
 
Introduction to Matrices
Introduction to MatricesIntroduction to Matrices
Introduction to Matrices
 
presentation on matrix
 presentation on matrix presentation on matrix
presentation on matrix
 
Matrices & Determinants
Matrices & DeterminantsMatrices & Determinants
Matrices & Determinants
 
Matrix.
Matrix.Matrix.
Matrix.
 
MATRICES
MATRICESMATRICES
MATRICES
 
Direct Methods For The Solution Of Systems Of
Direct Methods For The Solution Of Systems OfDirect Methods For The Solution Of Systems Of
Direct Methods For The Solution Of Systems Of
 
Determinants
DeterminantsDeterminants
Determinants
 
Matrix algebra
Matrix algebraMatrix algebra
Matrix algebra
 
Matrices And Determinants
Matrices And DeterminantsMatrices And Determinants
Matrices And Determinants
 

Viewers also liked (10)

Multivariate normal proof
Multivariate normal proofMultivariate normal proof
Multivariate normal proof
 
Estimation theory 1
Estimation theory 1Estimation theory 1
Estimation theory 1
 
Augmenting Data Structures
Augmenting Data StructuresAugmenting Data Structures
Augmenting Data Structures
 
Sufficient statistics
Sufficient statisticsSufficient statistics
Sufficient statistics
 
Session 9 10
Session 9 10Session 9 10
Session 9 10
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
A Measure Of Independence For A Multifariate Normal Distribution And Some Con...
A Measure Of Independence For A Multifariate Normal Distribution And Some Con...A Measure Of Independence For A Multifariate Normal Distribution And Some Con...
A Measure Of Independence For A Multifariate Normal Distribution And Some Con...
 
lecture 11
lecture 11lecture 11
lecture 11
 
Next higher number with same number of binary bits set
Next higher number with same number of binary bits setNext higher number with same number of binary bits set
Next higher number with same number of binary bits set
 
Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8Algorithm Design and Complexity - Course 8
Algorithm Design and Complexity - Course 8
 

Similar to median and order statistics

lecture 1
lecture 1lecture 1
lecture 1
sajinsc
 
Skiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksortSkiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksort
zukun
 
Sienna 3 bruteforce
Sienna 3 bruteforceSienna 3 bruteforce
Sienna 3 bruteforce
chidabdu
 

Similar to median and order statistics (20)

algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Ada notes
Ada notesAda notes
Ada notes
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring Algorithm
 
M269 Data Structures And Computability.docx
M269 Data Structures And Computability.docxM269 Data Structures And Computability.docx
M269 Data Structures And Computability.docx
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
 
02 Notes Divide and Conquer
02 Notes Divide and Conquer02 Notes Divide and Conquer
02 Notes Divide and Conquer
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 
Slide2
Slide2Slide2
Slide2
 
finding Min and max element from given array using divide & conquer
finding Min and max element from given array using  divide & conquer finding Min and max element from given array using  divide & conquer
finding Min and max element from given array using divide & conquer
 
lecture 1
lecture 1lecture 1
lecture 1
 
Skiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksortSkiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksort
 
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDEDFACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
 
Es272 ch2
Es272 ch2Es272 ch2
Es272 ch2
 
Sienna 3 bruteforce
Sienna 3 bruteforceSienna 3 bruteforce
Sienna 3 bruteforce
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
 
Brute force method
Brute force methodBrute force method
Brute force method
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
 
Basic of Statistics
Basic of StatisticsBasic of Statistics
Basic of Statistics
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 

More from Shashank Singh (7)

relational algebra
relational algebrarelational algebra
relational algebra
 
graph theory
graph theorygraph theory
graph theory
 
Network layer
Network layerNetwork layer
Network layer
 
Fibonacci numbers And Lucas numbers
Fibonacci numbers And  Lucas numbersFibonacci numbers And  Lucas numbers
Fibonacci numbers And Lucas numbers
 
Self organising list
Self organising listSelf organising list
Self organising list
 
Micro programmed control
Micro programmed  controlMicro programmed  control
Micro programmed control
 
Execution of functions
Execution of functionsExecution of functions
Execution of functions
 

Recently uploaded

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
parmarsneha2
 

Recently uploaded (20)

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 

median and order statistics

  • 2. Order statistics ith order statistic is the ith smallest element of a set of n elements. We will consider some special cases of the order statistics : The minimum, i.e. the first(i=1), the maximum, i.e. the last(i=n), and the median, i.e. the “halfway point." If n is odd, the median is unique, and if n is even, there are two medians(lower median and upper median).
  • 3. Selection problem It is a problem of computing where Input: A set A of n distinct numbers and a number i, with 1 i  n. Output: the element x  A that is larger than exactly i – 1 other elements of A.
  • 4. Naïve Solution We can simply sort the given numbers using heap or merge sort and then simply giving the output as ith index of the array. If we use a sorting algorithm then the selection problem can be solved in in O(n lg n) time. But using a sorting is more like using a cannon to shoot a fly since only one number needs to computed. So we will just find out that number. Before that let us solve the problem of selecting the minimum and maximum of a given set of number.
  • 5. Minimum and Maximum Minimum (A) 1. min = A[1] 2. for i = 2 to A.length 3. if min > A[i] 4. Min = A[i] 5. return min Maximum can be determined similarly.
  • 6. How many comparisons are necessary and sufficient for computing both the minimum and the maximum? Well, to compute the minimum n-1 comparisons are necessary and sufficient. The same is true for the maximum. So, the number should be 2n-2 for computing both. Is it possible to find out the minimum and maximum in less than 2n-2 comparisons? YES , lets see how…..
  • 7. Simultaneous Minimum and Maximum Simultaneous computation of maximum and minimum can be done in at most 3n/2 steps. Idea: Maintain the variables min and max. Process the n numbers in pairs. For the first pair, set min to the smaller and max to the other. After that, for each new pair, compare the smaller with min and the larger with max. Lets see the algorithm.
  • 8. MAX-AND-MIN(A , n) 1. max = A[n], min = A[n] 2. for i = 1 to n/2 3. if A[2i - 1] ≥ A[2i] 4. { if A[2i - 1] > max 5. max = A[2i - 1] 6. if A[2i] < min 7. min = A[2i] } 8. else { if A[2i] > max 9. max = A[2i] 10. if A[2i - 1] < min 11. min A[2i - 1] } 12. return max and min
  • 9. Randomized-Select Randomized-Select (A, p, r, i) 1. if p = r 2. return A[p] 3. q = Randomized-Partition(A, p, r) 4. k =q – p + 1 5. if i = k 6. return A[q] 7. else if i < k 8. return Randomized-Select(A, p, q – 1, i) 9. else return Randomized-Select(A, q+1, r, i – k)
  • 10. … Randomized-Partition(A, p, r) 1. i = random(p,r) 2. exchange A[r] with A[i] 3. return Partition(A, p, r) Partition(A, p, r) 1. x=A[r] 2. i=p-1 3. for j=p to r-1 4. if A[j]≤x 5. i=i+1 6. exchange A[i] with a[j] 7. exchange A[i+1] with A[r] 8. return i+1
  • 11. Example 6 10 13 5 8 3 2 11 i=7
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.