retagged by
1,078 views
1 votes
1 votes
Does this question makes sense to you? Its asked in algorithms section. Though quick googling says its all about statistics. Or I am making mistake and it is indeed part of Algorithms? Is it even in the syllabus?

The ith order statistics can be selected from an array of n elements in a minimum time that is:
(A) O(n)      (B) O(log n)      (C) O(n log n)       (D) None of these
retagged by

1 Answer

Best answer
2 votes
2 votes

The ith order statistic of a set of n elements is the ith smallest element.

How can we find the ith order statistic of a set and what is the running time?

Input: A set A of n (distinct) number and a number i, with 1 <= i <= n.

Output: The element x ∊ A that is larger than exactly i–1 other elements of A.

The selection problem can be solved in O(nlogn) time. Sort the numbers using an O(nlogn)‐time algorithm, such as heapsort or merge sort.Then return the ith element in the sorted array.


In fact, selection of the ith smallest element of the array A can be done in O(n) time. So We can use a randomized version .

Randomized-Select(A, p, r, i)
 if (p = r  )
 return A[p];
 q =Randomized-Partition(A, p, r)
 k=q-p+1;
 if(i==k)
 return A[q];
 else if(i<k)
return Randomized-Select(A, p, q-1, i)
else return Randomized-Select(A, q+1, r, i - (q - p + 1))

 The best case: always recurse on a subarray that has half of th elements smaller than the previous subarray.

$T(n) = T(n/2 ) + O(n) = O(n)$

The worst case: always recurse on a subarray that is only 1 element smaller than the previous subarray.
$T(n) = T(n - 1) + O(n)= O(n^{2})$.

Here we have expected running time $O(n)$ but due to bad partion worst case is $O(n^{2})$.

Even we can optimize the worst case using deterministic version. Which also takes Linear time.

Select(A,n,i):
    Divide input into ⌈n/5⌉ groups of size 5.

    /* Partition on median-of-medians */
    medians = array of each group’s median.
    pivot = Select(medians, ⌈n/5⌉, ⌈n/10⌉)
    Left Array L and Right Array G = partition(A, pivot)

    /* Find ith element in L, pivot, or G */
    k = |L| + 1
    If i = k, return pivot
    If i < k, return Select(L, k-1, i)
    If i > k, return Select(G, n-k, i-k)

Reference:  Order Statistics

So The ith order statistic of a set of n elements can be found in O(n) time.

selected by

Related questions

0 votes
0 votes
2 answers
1
bahirNaik asked Jan 15, 2016
2,260 views
0 votes
0 votes
1 answer
2
pC asked Dec 20, 2015
508 views
Q1 ) j = $\frac{n}{2}$ + $\frac{n}{4}$ + $\frac{n}{8}$ + ....... + 1 = O ( ?? )Q 2 ) j = 1 + $\frac{1}{2}$ + $\frac{1}{3}$ + $\frac{1}{4}$ +..... = O ( ?? )Q3 )while ...
0 votes
0 votes
0 answers
3
pC asked Dec 19, 2015
246 views
a) Order of finding k th Root ( express in terms of k and n where k represent 3 for cube root , n represent size of input )
1 votes
1 votes
1 answer
4
LavTheRawkstar asked Mar 25, 2017
2,584 views
Number of Cateogires are 5, Thier total weights are w1,w2,w3,w4,w5={7,2,4,8,6}b1,b2,b3,b4,b5={5,6,4,3,2}M=6=Maximum Capacity= WI am having confusion How to solve using dy...