Skip to main content

Posts

Max Heap

Recent posts

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.

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

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: Function which linearly proceeds through array. 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.

Selection Sort

 Let's begin! Selection Sort is a Sorting Algorithm which has two parts: Find the minimum element in the list within the given range. Swapping the present element with the present minimum element. One function will returns the smallest element's index within the given range and another element will swap the element with minimum element.

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.

Jump Search

 Let's begin! It's a Searching Algorithm with average time complexity as root n. Instead of going one by one through elements (like linear search), it jumps from element to element in a sorted array. The jump value is root of the length of array. If target element is found return true. Else If  current element is less than target and within the range call the function with change parameters. Else If  current element is greater than target and within the range call the function with change parameters. Else return false.