DATA STRUCTURE : Sorting
Bubble Sort
The bubble sort algorithm works by repeatedly swapping adjacent elements that are not in order until the whole list of items is in sequence. Items can be seen as bubbling up the list according to their key values.
Advantage
Bubble sort is easy to implement. Elements are swapped in place without using additional temporary storage, so the space requirement is at a minimum.
Disadvantage
Bubble sort doesn't deal well with a list containing a huge number of items. This is because the bubble sort requires n-squared processing steps for every n number of elements to be sorted.
Output :
Selection Sort
The selection sort works by repeatedly going through the list of items, each time selecting an item according to its ordering and placing it in the correct position in the sequence.
Advantage
The main advantage of the selection sort is that it performs well on a small list. Because it is an in-place sorting algorithm, no additional temporary storage is required beyond what is needed to hold the original list. Its performance is easily influenced by the initial ordering of the items before the sorting process.
Disadvantage
Selection sort is poor efficiency when dealing with a huge list of items, the selection sort requires n-squared number of steps for sorting n elements.
Output :
Insertion Sort
The insertion sorts repeatedly scan the list of items, each time inserting the item in the unordered sequence into its correct position.
Advantage
The main advantage of the insertion sort is its simplicity. It also exhibits a good performance when dealing with a small list. The insertion sort is an in-place sorting algorithm, so the space requirement is minimal.
Disadvantage
Insertion sort doesn't perform as well as other, better sorting algorithms. With n-squared steps required for every n element to be sorted, the insertion sort does not deal well with a huge list. The insertion sort is particularly useful only when sorting a list of few items.
Output :
Comments
Post a Comment