insertion tree
insertion tree
The Interval Tree is a self-balancing binary search tree that helps efficiently store and query intervals.
Let’s break down its construction step by step.
Each node in the tree represents an interval (low,high)(low, high)(low,high) and contains:
Example Input:
(15,20),(10,30),(17,19),(5,20),(12,15),(30,40)(15, 20), (10, 30), (17, 19), (5, 20), (12, 15), (30, 40)
(15,20),(10,30),(17,19),(5,20),(12,15),(30,40)
The insertion of an interval into the tree follows the BST property, where:
Insertion Algorithm:
Since the tree is empty, the first interval becomes the root:
(15, 20) [20]
/ \
/ \
Updating max:
o max(30,19) = 30 at (15,20)
/ \
/ \
Updating max:
/ \
/ \ \
Updating max:
o max(19,40) = 40 at (17,19).
o max(30,40) = 40 at (15,20).
Result: