Inserting an Element in Interval Heaps
Depending on the number of elements which are present in the interval heap, following cases are possible -
- Odd number of elements: If the number of elements in the interval heap be odd, the new element is inserted in the last node at first. Then, it is compared with the previous node elements successively and tested to meet the criteria essential for an interval heap. In case if the element does not meet any of the criteria, it is transferred from the last node to the root until all the conditions are met.
- Even number of elements: If the number of elements be even, then for the insertion of a new element an extra node is created. If the element falls or belongs to the left of the parent interval, it is treated to be in the min heap and if the element belongs or falls to the right of the parent interval, it is treated in the max heap. Further, it is compared successively and transferred from the last node to the root until all the conditions for interval heap are satisfied. If the element lies or belongs within the interval of the parent node itself, the process is terminated then and there itself and transferring of elements is not accomplished. The time required for inserting an element is depended on the number of movements required to satisfy all the conditions and is O(log n).
Published on 02-Jan-2020 12:23:40