algorithm - Java implementation of quickselect-median -


there implementation at

http://www.java-tips.org/java-se-tips/java.lang/quickselect-implementation-with-median-of-three-partitioning-and-cutoff.html

using scala syntax

val arr = array[comparable[_]](1, 7, 10, 11, 3, 6, 0, 2, 9, 4, 8, 5) quickselect(arr, 6) println(s"${arr.mkstring(" ")} | ${arr(6)}") 

and output: 1 4 2 0 3 5 11 10 9 7 8 6 | 11 . so, median 11 instead of 6. know bug in implementation?

link provided says that

* quick selection algorithm. * places kth smallest item in a[k-1]. 

6th element in zero-based array a[5]


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -