Skip to main content

Max Heap

 Let's begin!


Max Heap is a Binary Tree whose parent node will always have greater value than the child node.  

The representation of Max Heap in array is below:


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

Interpolation Search

 Let's begin! Interpolation search works better than Binary Search for a Sorted and Uniformly Distributed array. Binary Search goes to the middle element to check irrespective of search-key. On the other hand, Interpolation Search may go to different locations according to search-key. pos = lo + [ (x-arr[lo])*(hi-lo) / (arr[hi]-arr[Lo]) ] The idea of formula is to return higher value of pos When element to be searched is closer to arr[hi]. And Smaller value when closer to arr[lo] pos = lo + [ (x-arr[lo])*(hi-lo) / (arr[hi]-arr[Lo]) ] arr[] ==> Array where elements need to be searched x     ==> Element to be searched lo    ==> Starting index in arr[] hi    ==> Ending index in arr[]