kbest algorithm implementation from http://www.scielo.br/scielo.php?script=sci_arttext&pid=S0101-74382000000100011