algorithm - Java implementation of quickselect-median -
there implementation at
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
Post a Comment