Pseudocode for computing the median of an array A[0, 1, 2, ..., n-1]
01 SelectMedian(A[0, 1, 2, ..., n-1])
02 BubbleSort(A) or SelectionSort(A)
03 if n is odd then
04 r <- A[(n-1)/2]
05 else
06 r <- (A[n/2] + A[(n/2)-1)])/2
07 end if
08 return r
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment