0% found this document useful (0 votes)
36 views8 pages

Order of Algorithm

The document discusses medians and order statistics. It defines the ith order statistic as the ith smallest element of a data set. The minimum is the first order statistic and the maximum is the nth order statistic. A median is the "halfway point" - for odd numbers of elements it is the middle element, and for even numbers it is the average of the two middle elements. Algorithms for finding the maximum, minimum, and median are presented.

Uploaded by

Ravneet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views8 pages

Order of Algorithm

The document discusses medians and order statistics. It defines the ith order statistic as the ith smallest element of a data set. The minimum is the first order statistic and the maximum is the nth order statistic. A median is the "halfway point" - for odd numbers of elements it is the middle element, and for even numbers it is the average of the two middle elements. Algorithms for finding the maximum, minimum, and median are presented.

Uploaded by

Ravneet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Medians and Order

Statistics

Medians and Order Statistics


The ith order statistic of a set of n elements
is the ith smallest element.
For example, the minimum of a set of
elements is the first order statistic (i = 1), and
the maximum is the nth order statistic (i = n).
A median, informally, is the halfway point of
the set. When n is odd, the median is unique,
occurring at i = (n+1)/2.
When n is even, there are two medians,
occurring at i = n/2 and i = n/2 + 1.

University Institute of Engineering (UIE)

Medians and Order Statistics

Straight MaxMin(a,n,max,min)
{ max:=min:=a[1];
for(i:=2 to n do
{
if(a[i]>max) then max:=a[i];
if (a[i]<min) then min:=a[i];
}
}
University Institute of Engineering (UIE)

Medians and Order Statistics


MINIMUM(A)
1 min A[1]
2 for i 2 to length[A]
3 do if min > A[i ]
4 then min A[i ]
5 return min

University Institute of Engineering (UIE)

Finding the Max and Min


Algorithm MaxMin (i,j,Max,min)
{ If (i=j) then max:=min:=a[i];
else if (i=j-1) then
{ if(a[i]<a[j]) then
{ max:=a[j]; min;=a[i]; }
else
{ max:=a[i]; min:=a[j]; }
}
else
{ mid:=(i+j)/2;
MaxMin (i,mid,max,min);
MaxMin ( mid+1,j,max1,min1);
If(max<max1) then max:=max1;
If(min>min1) then min:=min1;
}
}

University Institute of Engineering (UIE)

Medians and Order Statistics


Example
a: [1]

[2] [3]

[4]

22

13 -5

-8

[5]

15

[6]

60

[7]

17

[8]

[9]

31

47

University Institute of Engineering (UIE)

Example

9
1,9,60,-8

6,9,60,17

1,5,22,-8
4

3
1,3,22,-5

4,5,15,-8

6
6,7,60,17

1,2,22,13

3,3,-5,-5

University Institute of Engineering (UIE)

7
8,9,47,31

References
Fundamental of Computer Algorithms ,2nd
Edition,Sartaj Sahni, Ellis Horowitz, Sanguthevar
Rajasekaran, Chapter No.3 page no.153-158.

University Institute of Engineering (UIE)

You might also like