SORTING ALGORITHMS IN PYTHON

INSERTION SORT

Insertion sort algorithm places an unsorted element at its suitable place in each iteration and it’s suitable place in each iteration and it’s similar as we sort cards in our hand in a card game.

It is efficient for smaller data sets, but very inefficient for larger lists.

COMPLEXITY OF INSERTION SORT

Time Complexity O(n2)

SELECTION SORT

Selection sort algorithm selects the smallest element from an unsorted list in each iteration and places that elements at the beginning of the unsorted list.

It is called selection sort because it repeatedly selects the next-smallest element and swaps it into the right place.

COMPLEXITY OF SELECTION SORT

Time Complexity O(n2)

BUBBLE SORT

Bubble sort is a simple algorithm which compares all the element one by one and sort them based on their values. The order can be ascending or descending.

COMPLEXITY OF BUBBLE SORT

Time Complexity O(n2)

MERGE SORT

Merge sort is based on the concept of Divide and Conquer in this concept we divide a problem into sub problems. When the solution to each sub problem is ready, we combine the results from the sub problems to solve the main problem.

COMPLEXITY OF MERGE SORT

Time Complexity O(n*log n)

QUICK SORT

Quick sort is also based on the concept of Divide and Conquer and this algorithm first seslct Pivot or any element from the array.

This algorithm divides the list into three main parts

  • Elements less than the Pivot element.
  • Pivot element(Central element)
  • Elements greater than the Pivot element.

COMPLEXITY OF QUICK SORT

Time Complexity O(n* log n)

Leave a comment

Design a site like this with WordPress.com
Get started