1
ALGORITHM: INSERTION: STEP 1 : Get the number of elements for deap. STEP 2 : Set the root in such a way that it contains no element. STEP 3 : The elements in the left sub tree is a min-heap. Place the min element in the root of the min-heap. STEP 4 : The elements in the right sub tree is a max-heap. Place the max element in the root of the max-heap. STEP 5 : If the right sub tree is not empty, then let i be any node in the left sub tree. STEP 6 : Let j be the corresponding node in the right sub tree. If such a j does not exist, then let j be the node in the right sub tree that corresponds to the parent of i. The key in node i is less than or equal to the key in j. STEP 7 : Insert the element in such a way that the deap property is not violated.

ALGORITHM.docx

Embed Size (px)

Citation preview

ALGORITHM:

INSERTION:

STEP 1 : Get the number of elements for deap.STEP 2 : Set the root in such a way that it contains no element.STEP 3 : The elements in the left sub tree is a min-heap. Place the min element in the root of the min-heap.STEP 4 : The elements in the right sub tree is a max-heap. Place the max element in the root of the max-heap.STEP 5 : If the right sub tree is not empty, then let i be any node in the left sub tree. STEP 6 : Let j be the corresponding node in the right sub tree. If such a j does not exist, then let j be the node in the right sub tree that corresponds to the parent of i. The key in node i is less than or equal to the key in j.STEP 7 : Insert the element in such a way that the deap property is not violated.