SORTING
Sorting refers to arranging elements in a specific order which can either be Ascending (increasing order) or Descending (decreasing order).
For instance -

There are multiple ways or techniques to sort a group of elements. Some known algorithms are,
- Bubble sort
- Insertion sort
- Selection sort
- Heap sort
- Quick sort
- Merge sort etc…
We will discuss the working and algorithm of Bubble, Selection, and Insertion sort.
Bubble Sort in Python
Bubble sort compares two adjoining values and exchanges them if they are not in the proper order.
In this, the heaviest element or the greatest number comes at the bottom within the initial iteration.
Algorithm
- for i in range len(L):
- for j in range (0,len(L)-1):
- if (L[j]>L[j+1]):
- temp=L[j]
- L[j]=L[j+1]
- L[j+1]=temp

Working


Insertion Sort in Python
Insertion sort is an algorithm that builds a sorted list, one element at a time from the unsorted list by inserting the element at its correct position in the sorted list.








sairam nagothuPosted Sep 23, 2019, 1:07 AM
Nice explanation .. #short and sweet
Elavarasan RPosted Sep 21, 2019, 9:05 AM
Great. clear explanation.