How to find the kth minimum element in an array [on hold]

I am looking for an efficient algorithm to find the k'th minimum
element in an unsorted array of n elements, where 1 <= k
<= n . The obvious thing is to sort the array first, then
pick the k'th element, which will result in a running time of
O(n * log(n)) But I guess it can be done in a more
efficient way, since sorting the array seems to do "too much". For
example, for k=1 the task is to find the minimum of the array, which
can be done in O(n) .
Does anyone know a better algorithm for k>=2?


I have data set with thousands values as following in a vector:
1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6,
6
The property of the data:
1) The values are consecutive integers by starting from 1.
2) The number of each value is not always the same.
The aim:
Find the minimum and maximum index of each value in the vector.The
expected result should be:
minimum index: [0, 3,5,9,14,16]
maximum index: [2, 4,8,13,15,20]
Could some one give me easy solution?
Thanks

Web Development 

I making book reader web application. And i view all text of book
in one element. For make page simulation i make scroll element. One
page is the viewport of user.
Some times text is broken. And i need to hide that text. How I can
quickly find the breaking element? elementFromPoint is good, but it
finds only parent element. I find a decision to check all elements
position by recusive function by condition some think like this
if (element.top < book.top && book.top <
element.bottom)
Its works, but it works without good performance for long books.
How i can resolve it?
Demo:
rel="nofollow">http://jsfiddle.net/SHfz4/14/ red text is broken
and i want to get to him and hide him.

Web Development 

I was going through the question how to find kth smallest element
in unsorted array.
I read following algorithm
using concept of randomized partitioning ( O(n) )
as per the cousera.
randomized function guarantee not have worst case.
so we come upd following equation.
T(n) = T(n/2) + c ( on average)
Median of median of median ( O(n))
as per wiki
T(n) = T(2n/10) + T(7n/10) + cn.
Both algorithm give o(n), so which one will be better?
which alog is to use where, any example will be good.

Web Development 

I have an array with N elements (not sorted). Each element of the
array can be any integer (positive or negative). Now I have to
partitioned this array in a way that absolute(sum(sub_array1) 
sum(sub_array2)) is minimal.
Example:
A = {3, 4, 1, 2, 5}
partition1 = sub_array1 {3}, sub_array2 {4, 1, 2, 5} => abs(32) =
1
partition2 = sub_array1 {3, 4}, sub_array2 {1, 2, 5} =>
abs(7(2)) = 9
partition3 = sub_array1 {3, 4, 1}, sub_array2 {2, 5} =>
abs(8(3)) = 11
partition4 = sub_array1 {3, 4, 1, 2}, sub_array2{5} =>
abs(10(5)) = 15
Answer = 1
I have achieved the solution with O(N^2), but I want to do it with
at least O(Nlog(N)), and without threading (parallel solution).

Web Development 

I came across the solution for this problem:
I would like to know the concept behind selecting the low and high
values?
int findKthSmallest(int arr1[],int size1,int arr2[],int
size2,int k)
{
//check whether we have k element after combining both arrays.
assert(size1 + size2 >= k);
assert(k>0);
//find index low <= w < high such that w from arr1 and (kw)
from arr2, are the smallest k numbers of resultant.
int low = max(0 , k  size2 ); //define start point
int high = min(size1 , k);//define end point
while (low < high)
{
int w = low + (high  low) /2;
//Can we include arr1[w] in the k smallest numbers that we are
finding?
if ((w < size1) && (kw > 0) && (arr1[w]
< arr2[kw1]))
{
low = w + 1;
}
else if ((w> 0) && (kw < size2 ) &&
(arr1[w1] > arr2[kw]))
{
//can we discard arr1[w l] from the set of k smallest
numbers.
high = w;
}
else
{
//Both the inequalities were false, break.
low = w;
break;
}
}
if (low == 0)
{
return arr2[k 1];
}
else if (low == k)
{
return arr1[k1];
}
else
{
return max(arr1[low 1], arr2[k  low  1]);
}
return 0;
}

Programming Languages 

I am looking for an efficient algorithm to find the k'th minimum
element in an unsorted array of n elements, where 1 <= k
<= n . The obvious thing is to sort the array first, then
pick the k'th element, which will result in a running time of
O(n * log(n)) But I guess it can be done in a more
efficient way, since sorting the array seems to do "too much". For
example, for k=1 the task is to find the minimum of the array, which
can be done in O(n) .
Does anyone know a better algorithm for k>=2?

Programming Languages 


