Averages/Median: Difference between revisions

Content deleted Content added
m add cross link
corrected categorization of task
Line 1: Line 1:
{{task|Arithmetic operations}}Write a program to find the [[wp:Median|median]] value of a vector of floating-point numbers. The program need not handle the case where the vector is empty, but ''must'' handle the case where there are an even number of elements.
{{task|Probability and statistics}}Write a program to find the [[wp:Median|median]] value of a vector of floating-point numbers. The program need not handle the case where the vector is empty, but ''must'' handle the case where there are an even number of elements.


There are two approaches to this. One is to sort the elements, and then pick the one in the middle. Sorting would take at least O(n log n). The other solution is to use the [[wp:Selection algorithm|selection algorithm]] to find the median in O(n) time.
There are two approaches to this. One is to sort the elements, and then pick the one in the middle. Sorting would take at least O(n log n). The other solution is to use the [[wp:Selection algorithm|selection algorithm]] to find the median in O(n) time.