sorting - algorithm to find the median value from an array with an odd number of elements -
this question has answer here:
- finding median of unsorted array 6 answers
i know if there exists algorithm find median of array of odd length. 1 sort array , take middle ideally being interested in median 1 make gains in terms of time complexity of algorithm.
if no such algorithm exists, suggestions regarding how go developing such algorithm great.
thanks
this solved selection algorithm, , can done in o(n)
time. quickselect, or refinement introselect, popular methods.
a brief summary of quickselect run quicksort, rather sorting both halves @ each step, sort half contains element you're looking for, can determined counting how many elements in each partition.
c++, example, has standard library function: nth_element.
Comments
Post a Comment