Understanding Heap Data Structure Implementation
Explore the implementation of a heap data structure through a complete binary tree concept, array representation, adding elements, removing elements, and avoiding swaps. Learn the steps involved in adding, removing, and organizing elements within a heap for efficient data storage and retrieval.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
A Heap Implementation Chapter 26 1 Adapted from Pearson Education, Inc.
Heaps (ch23) Complete binary tree: nodes contain Comparable objects Organization Each node contains object no smaller (or no larger) than objects in descendants Maxheap, object in node greater than or equal to descendant objects Minheap, object in node less than or equal to descendant objects 2 Adapted from Pearson Education, Inc.
Reprise: The ADT Heap Interface considered in Chapter 23 Listing 23-6 3 Adapted from Pearson Education, Inc.
Example 4 Adapted from Pearson Education, Inc.
Array to Represent a Heap Begin by using array to represent complete binary tree. Complete tree is full to its next-to-last level Leaves on last level are filled from left to right Locate either children or parent of any node by performing simple computation on node s number 5 Adapted from Pearson Education, Inc.
The steps in adding 85 to a maxheap 6 Adapted from Pearson Education, Inc.
A revision of the steps to avoid swaps 7 Adapted from Pearson Education, Inc.
An array representation of the steps 8 Adapted from Pearson Education, Inc.
An array representation of the steps 9 Adapted from Pearson Education, Inc.
RemoveMax 10 Adapted from Pearson Education, Inc.
Adding 20, 40, 30, 10, 90, and 70 11 Adapted from Pearson Education, Inc.
The steps in creating a heap of the entries 20, 40, 30, 10, 90, and 70 by using reheap 12 Adapted from Pearson Education, Inc.
The steps in creating a heap of the entries 20, 40, 30, 10, 90, and 70 by using reheap 13 Adapted from Pearson Education, Inc.
Figure 26-9 A trace of heap sort 14 Adapted from Pearson Education, Inc.
Figure 26-9 A trace of heap sort 15 Adapted from Pearson Education, Inc.
Figure 26-9 A trace of heap sort 16 Adapted from Pearson Education, Inc.
Efficiency 17 Adapted from Pearson Education, Inc.