Sorting Algorithms Explained

Xybernetics Inc

Sorting Algorithm Explained... GIF Style

There are various types of sorting technique which offers different speeds for different types of initial data arrangements. I am not about to sit down here and type a length narrative explaning how each of them functions. Better yet, I will let the animated GIF do the talking.

The recources (like the animated gifs, codes, pseudocode, algorithm) in this webpage do not belong to me. The credit goes to all the hardworking developers and publishers which is listed my my Reference list below.



Xybernetics Inc Bubble Sort

Example 1
Xybernetics Inc - Bubble Sort


Example 2
Xybernetics Inc - Bubble Sort

Key Notes
- Bubble sort takes Ο(n2)

Algorithm



Pseudocode



Example Code in C#


Output




Xybernetics Inc Insertion Sort

Key Notes
- Average and worst case complexities are of Ο(n2), where n is the number of items
- Uses nested looping

Example 1
Xybernetics Inc - Insertion Sort Example 01

Example 2
Xybernetics Inc - Insertion Sort Example 02

Algorithm



Pseudocode



Example Code in C#


Output




Xybernetics Inc Selection Sort

Key Notes
- Keeps track of "sorted" and "unsorted" index
- Looks for lowest from the "unsorted" side of array
- Swaps position with first value in the "unsorted" side
- "Sorted" side numbers are never revisited (assume it has been sorted)
- Swapping is done on the "unsorted" side only.
- Average and worst case complexities are of Ο(n2), where n is the number of items
- Ineffecient sorting algorithm for large amounts of data, it is prefered for very small amounts of data

Example 1
Xybernetics Inc - Selection Sort

Example 2
Xybernetics Inc - Selection Sort

Algorithm



Pseudocode



Example Code in C#


Output




Xybernetics Inc Merge Sort

Key Notes
- Worst-case time complexity being O(n log n)

Example 1
Xybernetics Inc - Merge Sort

Algorithm



Pseudocode



Example Code in C#


Output




Xybernetics Inc Heap Sort


Example 1
Xybernetics Inc - Heap Sort


Example 2
Xybernetics Inc - Heap Sort

Algorithm



Pseudocode



Example Code in C#



Xybernetics Inc Quick Sort

Key Notes
- Average and worst case complexity are of O(nlogn), where n is the number of items

Example 1
Xybernetics Inc - Quick Sort


Example 2
Xybernetics Inc - Quick Sort


Example 2
Xybernetics Inc - Quick Sort

Algorithm



Pseudocode



Example Code in C#


Output




Which Algorithm Is For Me?

It depends heavily on details of the application and implementation. The table below summarizes the important characteristics of the sort algorithms.

Growth Rate to Srot N Items
Alorithm        Stability        Inplace         Running Time        Extra Space        Note
Insertion Yes Yes Between n and n2 1 Depends on the order of the input key
Selection No Yes n2 1 
Bubble Yes Yes n2 1 
Merge Yes No nlogn n 
Heap No Yes nlogn n 
Quick No Yes nlogn logn Probabilistic


Xybernetics Inc


Sorting speed based on data arrangement types.

Xybernetics Inc - Sorting Speed



Reference

The animated GIF shown here are by no means any of my material. I got them from the website below.