Initializing an Interval Heap

Data Structure AlgorithmsAnalysis of AlgorithmsAlgorithms

An interval heap is same as an embedded min-max heap in which each node contains two elements. It is defined as a complete binary tree in which

  • The left element is smaller than or equal to the right element.
  • Both the elements define a interval which is closed.
  • Interval represented by any node other than the root is a sub-interval of the parent node.
  • Elements on the left hand side represent a min heap.
  • Elements on the right hand side represent a max heap.

Depending on the number of elements, two cases are permitted -

  • Even number of elements: In this case, each node contains two elements say a and b, with a ≤ b. Every node is then represented by the interval [a, b].
  • Odd number of elements: In this case, each node other than the last contains two elements represented by the interval [a, b] whereas the last node will contain a single element and is represented by the interval [a, b].

Interval heaps may be initialized implementing a strategy same as that used to initialize ordinary heaps--work our way from the heap bottom to the root ensuring that each sub tree is denoted as an interval heap. For each sub tree, first order the elements in the root; then again insert the left end point of this sub tree’s root implementing the reinsertion strategy used for the removeMin function, then again insert the right end point of this sub tree’s root implementing the strategy used for the removeMax function.

raja
Published on 03-Jan-2020 05:25:08
Advertisements