1 / 7

Heap Implementation: Inserting Elements and Adjusting Size Dynamically

This document details the process of dynamically inserting elements into a heap while managing its size. The initial size of the heap is noted, and the insertion of a new element follows specific conditions to maintain the heap's properties. We emphasize the importance of incrementing the heap size as necessary and the procedure to swap elements to ensure the correct arrangement. The algorithm showcases the repeated insertion of an element (25) and the adjustments made during the insertions, providing a comprehensive overview of heap operations.

tala
Télécharger la présentation

Heap Implementation: Inserting Elements and Adjusting Size Dynamically

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Insertion size = 26 2 26 10 18 21 29 27 57 20 47 37 69 69 29 58 The heap to start with... 86 90 31 94 55 98 71 95 85 79 91

  2. Insertion size = 27 2 Increment the size 26 10 18 21 29 27 57 20 47 37 69 69 29 58 25 86 90 31 94 55 98 71 95 85 79 91 Insert 25

  3. Insertion size = 27 2 26 10 18 21 29 27 57 20 47 37 69 69 29 58 while(A[i] < A[i/2]) { swap(A[i],A[i/2]); i = i/2; } 25 86 90 31 94 55 98 71 95 85 79 91 Insert 25

  4. Insertion size = 27 2 26 10 18 21 29 27 57 20 47 37 69 25 29 58 while(A[i] < A[i/2]) { swap(A[i],A[i/2]); i = i/2; } 69 86 90 31 94 55 98 71 95 85 79 91 Insert 25

  5. Insertion size = 27 2 26 10 18 21 25 27 57 20 47 37 69 29 29 58 while(A[i] < A[i/2]) { swap(A[i],A[i/2]); i = i/2; } 69 86 90 31 94 55 98 71 95 85 79 91 Insert 25

  6. Insertion size = 27 2 25 10 18 21 26 27 57 20 47 37 69 29 29 58 while(A[i] < A[i/2]) { swap(A[i],A[i/2]); i = i/2; } 69 86 90 31 94 55 98 71 95 85 79 91 Insert 25

  7. Insertion size = 27 2 25 10 18 21 26 27 57 20 47 37 69 29 29 58 69 86 90 31 94 55 98 71 95 85 79 91

More Related