classic algorithm of searching and selection