Linked Questions
11 questions linked to/from Find the 2nd largest element in an array with minimum number of comparisons
0 votes
3 answers
2k views
Search the biggest and second biggest number in O(n+logn) time [duplicate]
Possible Duplicate: Find the 2nd largest element in an array with minimum # of comparisom May I know how to achieve searching the biggest and second biggest number in O(n+logn) time? Thank you in ...
236 votes
32 answers
255k views
How to find the kth largest element in an unsorted array of length n in O(n)?
I believe there's a way to find the kth largest element in an unsorted array of length n in O(n). Or perhaps it's "expected" O(n) or something. How can we do this?
37 votes
5 answers
55k views
Sorting in place
What is meant by to "sort in place"?
4 votes
7 answers
10k views
Algorithm: Find index of 2nd smallest element from an unknown array
I have been pondering about my homework question for a while. I welcome (and prefer) any suggestions or approach on how to attack this problem. Basically, I have an array A of size N. We do not know ...
2 votes
6 answers
20k views
Find second maximum number in a list [duplicate]
First line contains N. Second line contains list of N integers each separated by a space. I need to find the second largest number in list. My code: N = int(raw_input()) L = map(int, raw_input().split(...
8 votes
2 answers
5k views
Interview Algorithm: find two largest elements in array of size n
This is an interview question I saw online and I am not sure I have correct idea for it. The problem is here: Design an algorithm to find the two largest elements in a sequence of n numbers. ...
6 votes
4 answers
2k views
Efficient way of computing second min value
Given a matrix, it's easy to compute the value and index of the min value: A = rand(10); [value, index] = min(A(:)); However I would also like to recover the second min value (idem for max). I can ...
2 votes
3 answers
2k views
How can I make an array without one number of the other array?
I am trying to make a code with two arrays. The second array has the same values of the first except for the smallest number. I have already made a code where z is the smallest number. Now I just want ...
4 votes
2 answers
2k views
how to track max/min of fifo query
I have fifo query where I put and eject doubles. After each update I need max and min values. I don't need position (or index) of these values in query. How to do that effectively? log(N) or probably ...
5 votes
1 answer
1k views
Is there a "tournament" algorithm to find k-th largest element?
I know that we can find the 2nd largest element in an array of size N in N+log(N)-2 using a "tournament" algorithm. Now I wonder if we can find the k-th largest element using a similar "tournament". ...
0 votes
1 answer
101 views
Find the Max and 4th Max element
To find the maximum and 4th Maximum of an array what is the minimum number of comparisons needed? I assume I have to use an algorithm similar to MinMax and the solution found here: Find the 2nd ...