This can be done using the concept of median of medians, wherein we can
achieve linear time complexity in the worst case.
This is a concept used in parallel algorithms too, check it out.

On Mon, Jun 18, 2012 at 5:38 PM, Prem Nagarajan <prem.cmna...@gmail.com>wrote:

> @enchantress : This problem can be solved using quicksort in O(nlogn). No
> need to go for selection sort.
> But O(n) solution is needed.
>
>
> On Mon, Jun 18, 2012 at 2:50 PM, enchantress <elaenjoy...@gmail.com>wrote:
>
>>
>> Hi all,
>> A variation of selection sort can be used which takes O(nk) time.
>>
>> for i 1 to k
>>   min_index = i
>>   for j i+1 to n
>>      if a[j] < a[min_index]
>>         min_index = j
>>   swap(a[i],a[min_index])
>>
>> required element : a[k]
>>
>> On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote:
>>
>>> Give an array of unsorted elements, find the kth smallest element in the
>>> array.
>>>
>>> The expected time complexity is O(n) and no extra memory space should be
>>> used.
>>>
>>> Quickselect algorithm can be used to obtain the solution. Can anyone
>>> explain how quickselect works?
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/algogeeks/-/FABBRabzVqMJ.
>>
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to