Skip to main content

Insertion Sort

Let's begin!

Insertion sort is a Sorting Algorithm which have average time complexity as polynomial square and best case as linear.

It has two function:
  1. Function which linearly proceeds through array.

  2. Helper Function to compare and swap the element if required within the given range.

If the function finds that right element is smaller then left element then it will call the helper function to compare and swap the elements if necessary.

Comments

Popular posts from this blog

Bubble Sort

 Let's begin! Bubble Sort is a Sorting Algorithm which has two parts: Bubbles up the largest element at the last. Keep checking if the list is sorted. One function will keep bringing the biggest elements at the last of the list and another function will recursively calling it until the list is sorted.

Merge Sort

 Let's begin! We've learned that Merge Sort is a sorting algorithm which follows the principle of Divide and Conquer and it have average time complexity as n(log n). I have used two functions to implement Merge Sort: 1. Merge Sort (To Produce Sub Array) It will divide array in two parts form left to mid and mid+1 to end. It will produce sub array until it's a single element. 2. Merge (To Merge Sorted Array) It will sort the array by comparing elements in left array and right array and store it into temporary array. It will save the remaining value. It will copy the temporary array into main array

Quick Sort

 Let's begin! Quick Sort is a sorting algorithm which follows the principle of Divide and Conquer with average time complexity as n(log n) and worst time complexity as n^2.  We have two functions to implement Quick Sort: Quick Sort Functions quickSort( )  Recursively call the function until start is less than end. partition( ) Swap elements to left which are less than pivot and brings pivot to it's ideal position.