70 likes | 228 Vues
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.
E N D
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
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
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
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
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
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
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