Design and Analysis Heapify Method


Advertisements

Heapify method rearranges the elements of an array where the left and right sub-tree of ith element obeys the heap property.

Algorithm: Max-Heapify(numbers[], i) 
leftchild := numbers[2i] 
rightchild := numbers [2i + 1] 
if leftchild ≤ numbers[].size and numbers[leftchild] > numbers[i] 
   largest := leftchild 
else 
   largest := i 
if rightchild ≤ numbers[].size and numbers[rightchild] > numbers[largest] 
   largest := rightchild 
if largest ≠ i 
   swap numbers[i] with numbers[largest] 
   Max-Heapify(numbers, largest)

When the provided array does not obey the heap property, Heap is built based on the following algorithm Build-Max-Heap (numbers[]).

Algorithm: Build-Max-Heap(numbers[]) 
numbers[].size := numbers[].length 
fori = ⌊ numbers[].length/2 ⌋ to 1 by -1 
   Max-Heapify (numbers[], i) 

Useful Video Courses


Video

Compiler Design Online Training

102 Lectures 10 hours

Arnab Chakraborty

Video

Sequential Circuit Design

30 Lectures 3 hours

Arnab Chakraborty

Video

Design Patterns Online Training

31 Lectures 4 hours

Arnab Chakraborty

Video

InDesign Online Training

43 Lectures 1.5 hours

Manoj Kumar

Video

Canva: Become a Graphic Designer

7 Lectures 1 hours

Zach Miller

Video

The Ultimate Canva Graphic Design Course

54 Lectures 4 hours

Sasha Miller

Advertisements