Definition: Selection sort also falls under the basic sorting algorithms but its performance is better than bubble sort because it reduces the number of swaps. Consider an array that needs to be sorted: Steps: 1. Start from the left and record the elements value. 2. Proceed down the array and compare the value of the element to the elements that are still available;if you find a element with a value smaller than the first one; keep a note of it. 3. If, while moving down the array you encounter any other smaller values than the one you have recorded; discard the previous one you have recorded and keep note of the current one you have found. 4. If you reach the end of the arrary then swap the smallest elements position with the first element(far left) and start the procedure from the beginning but increment the count by one because the first element is in its sorted position.
Link to this comment:
All Comments (0)