English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

What is the fastest way to get the median value from a list of numbers? A link to some code would be appreciated (VB6, C, or C#)

2006-12-13 06:14:25 · 2 answers · asked by Zefram 2 in Computers & Internet Programming & Design

2 answers

The simplest answer is usually to just sort the list and pick out the middle element. That takes O(n log n) time.

A faster (though a bit more complex) algorithm in O(n) time called the median-of-medians algorithm. Pseudo-code is available at:
http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general_selection_algorithm_-_.22Median_of_Medians_algorithm.22

2006-12-13 06:24:40 · answer #1 · answered by jfengel 4 · 0 0

i don't believe it truly is achievable, even with the undeniable fact that i'm no longer regularly occurring adequate with decision idea to provide a reliable evidence of it... i have tried doing it before, and that i have not arise with an set of guidelines that did not at one aspect type the values in some way... Chris S isn't that still sorting the list? I recommend, particular, it truly is dealing with and figuring out on a pattern median, then checking it, going to the subsequent, and so on... yet it truly continues to be sorting...purely in a unique (and probably some distance a lot less effectual) way...

2016-11-26 01:09:52 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers