Questions tagged [selection-problem]
68 questions
10
votes
4 answers
Finding the two largest of five small integers as quickly as possible
I use a variation of a 5-cross median filter on image data
on a small embedded system, i.e.
x
x x x
x
The algorithm is really simple: read 5 unsigned integer values, get the highest 2, do some calculations on those and write back the…
Fredrik Pihl
- 203
- 1
- 7
9
votes
2 answers
A median of an AVL. How to take advantage of the AVL?
Here is the source of my question.
Given a self-balancing tree (AVL), code a method that returns the
median.
(Median: the numerical value separating the higher half of a data
sample from the lower half. Example: if the series is
2, 7, 4, 9, 1,…
Maksim Dmitriev
- 413
- 1
- 3
- 14
6
votes
1 answer
(Nontrivial) Algorithms for finding the third largest element of a set
According to the lecture note by Jeff Erickson, the lower bound for finding the third largest element of a set of $n$ distinct elements is open. See the related post: What is the lower bound for finding the third largest in a set of $n$ distinct…
hengxin
- 9,671
- 3
- 37
- 75
6
votes
3 answers
Find two numbers in array $A$ such that $ |x-y| \leq \frac{\max(A)-\min(A)}n$ in linear time
I'm struggling with the following question:
Let $\langle a_0, a_1,\dots,a_n\rangle$ be a sequence of real numbers, and let $ M =
\max\{a_0, a_1, .... a_n\} $ and $ m = \min\{a_0, a_1, .... a_n\} $.
a. Prove that there are two numbers in the…
Avishay28
- 203
- 1
- 4
5
votes
5 answers
Algorithm for finding two smallest numbers in an array
I was just thinking today that the best approach to find two smallest numbers in any array would be to first sort(ascending order) it with some efficient algorithm like Quicksort(Average case complexity: nlogn) and then access the first two members…
Rajat Saxena
- 213
- 3
- 9
4
votes
2 answers
Time complexity of a precedence constrained selection problem
I wonder if you have an idea over the time complexity of the following problem, or a problem similar to this one (generally a selection problem)
[Assuming operations on integers take O(1) time]
We are given a set $N$ of $n$ items, that are subject…
Salim
- 43
- 5
3
votes
1 answer
Median of medians: bound on pivot position
If I understand correctly (from reading Wikipedia), median-of-medians pivot selection makes quickselect $O(n)$ because the pivot is guaranteed to be in between the 30th and 70th percentiles and so at least 30% of elements will be removed in each…
Alex Yu
- 33
- 3
3
votes
1 answer
Median of Medians Recurrence Relation for 3-grouping
So I am trying to figure out the recurrence relation for the median of medians algorithm using groups of 3 instead of groups of 5. Per CLRS's method, my recurrence relation looks like
$$
T(n) = T(\lceil \frac{n}{3} \rceil) + T(\frac{2n}{3} + 4) +…
wieiooof
- 71
- 1
- 6
3
votes
1 answer
$k$th Largest Algorithm in a range $[k, k+c]$
The well-known algorithm for computing the $k$-th largest element in an unsorted array of size $n$ runs in $O(n)$ time.
How about for a range $[k, k+c]$, where $c$ is not necessarily independent of $n, k$? The obvious "brute-force" algorithm is to…
Bob
- 61
- 1
- 5
3
votes
1 answer
Returning m greatest elements from k sorted array
We have $k$ sorted arrays, $A_1[1...n_1],...,A_k[1..n_k]$, where $n_1+n_2+...+n_k=n$.
How can we get the $m$ greatest elements in running time $O(k + m\lg k)$?
I have tried to use MIN-HEAP size of $k$ since we have $k$ arrays. I have to navigate…
Sami
- 163
- 3
3
votes
1 answer
Best sort method for median: median heap or insertion sort on a vector
I'm trying to decide between two methods of calculating a median, that will optimize the following operations:
Add integer to data structure (insert)
Get the median of all integer (getMedian)
The program will add a random number of integers (no…
Guest1995
- 31
- 2
3
votes
1 answer
Minimum number of comparision to find the third largest element in an array of distinct integers?
For the second largest element, I know that the formula is $n+ \lceil\log n \rceil -2 $
Is there any formula for the third largest element? and if so, what is the derivation?
user106464
3
votes
1 answer
Lower Bound for Time Complexity of Pairing Problem
Given an array X and array Y both of length n, the pairing algorithm will return the elements of the arrays matched so that the smallest element in X will be matched with the smallest element of Y, the second smallest in X matched with second…
marianov
- 141
- 1
- 7
3
votes
2 answers
Is finding Kth largest element using selection algorithm taking O(n) only if K is fixed?
Wikipedia here https://en.m.wikipedia.org/wiki/Selection_algorithm shows an algorithm using sort of quicksort.. in order to find Kth largest or smallest element taking O(n) time only on average. The point which is unclear is whether K is required to…
Barushkish
- 31
- 3
2
votes
0 answers
Help with deterministic selection algorithm
All we know what is Deterministic Selection Algorithm:
Line up elements in groups of five (this number $5$ is not important, it could be e.g. $7$ without changing the algorithm much). Call each group $S[i]$, with $i$ ranging from $1$ to…
letotyrazdeta
- 21
- 2