# Sorting Algorithms Explained 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. Bubble Sort

Example 1 Example 2 Key Notes
- Bubble sort takes Ο(n2)

Algorithm

Pseudocode

Example Code in C#

Output Insertion Sort

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

Example 1 Example 2 Algorithm

Pseudocode

Example Code in C#

Output 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 Example 2 Algorithm

Pseudocode

Example Code in C#

Output Merge Sort

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

Example 1 Algorithm

Pseudocode

Example Code in C#

Output Heap Sort

Example 1 Example 2 Algorithm

Pseudocode

Example Code in C# Quick Sort

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

Example 1 Example 2 Example 2 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 Sorting speed based on data arrangement types. Reference
 The animated GIF shown here are by no means any of my material. I got them from the website below.