Monday 15 April 2013

Buuble sort to find five most smallest element in an array -


I have an array list with some integer values, and I need to find only five smallest elements from the list. Is it able to use bubble sort using any other sorting algorithm? Or what is the best algorithm for it?

Common approach to using a binary pile n from one end The smallest element while scanning to the other.

However, for the five elements, it can be equally efficient to track the smallest of five ever so far. You inspect for each new element, if it is smaller than all the elements in the array, then replace the largest with the new element.

No comments:

Post a Comment