开发者

finding the middle value without sorting [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How to find the kth largest element in an unsorted array of length n in O(n)?

Is there any algorithm of finding the middle value of given list without performing the sorting operation.

for example if the list is maintained as stack and contains ( 1,2,5,3,4,6 ) then the middle value should be 4 so my question is how to get this value without performing t开发者_C百科he sorting operation on the list.

is this possible?


Yes, there are well-known algorithms to find the kth largest element of a list. See How to find the kth largest element in an unsorted array of length n in O(n)?

Here k is pre-computed as length/2 of course, adjusted to the nearest integer if there are an even number of elements in your list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜