HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Finding Specific Order Statistics with O(n log(n/k)) Complexity

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
orderlogwithfindingstatisticsspecificcomplexity

Problem

I'm working on a problem where I need to find specific order statistics in a set of numbers. Given n numbers, I want to determine the k-th smallest, the 2k-th smallest, and so on, up to the ⌊n/k⌋-th smallest element. I'm looking for a method to accomplish this with a time complexity of O(n log(n/k)).

My Attempt:

So far, I've considered using modified sorting algorithms and heap structures, but I'm not sure if these approaches can achieve the desired time complexity. I suspect there might be a more efficient way to find these specific elements without fully sorting the entire array.

Question:

Can anyone suggest an algorithm or method to find these elements with the required time complexity?

Solution

Find n/2k-th in $O(n)$ time. There are standard algorithms for finding any p-th smallest element in array in $O(n)$ time.

Partition the array in almost equal halves about this n/2k-th smallest element.
Run the algorithm recursively on the two halves. Once the algorithm finds all the required $n/k$ elements; return.

Note that the height of the recurrence tree is $O(\log(n/k))$. and in each level the algorithm is doing $O(n)$ comparison operations.

Thus, the overall running time is $O(n \log (n/k))$.

Context

StackExchange Computer Science Q#164963, answer score: 2

Revisions (0)

No revisions yet.