Design and Analysis Extract Method


Advertisements

Extract method is used to extract the root element of a Heap. Following is the algorithm.

Algorithm: Heap-Extract-Max (numbers[]) 
max = numbers[1] 
numbers[1] = numbers[heapsize] 
heapsize = heapsize – 1 
Max-Heapify (numbers[], 1) 
return max 

Example

Let us consider the same example discussed previously. Now we want to extract an element. This method will return the root element of the heap.

Method

After deletion of the root element, the last element will be moved to the root position.

Root Element

Now, Heapify function will be called. After Heapify, the following heap is generated.

Heapify

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