I am looking for a data structure that allows storing non-overlapping ranges of integers
and comparing whether a certain range exists[is covered] in[by] the data structure.
For example, after I store (0,9),(10,19),(30,29),
at some point later I want to check if the range (1,11) is covered, in which case the
algorithm gives a “yes” whereas with the range (15,25) the algorithm gives a “no” as the given range is not covered.
Many thanks in advance.
Since you’re dealing with non-overlapping ranges of integers, I think a simple BST could do the job(balanced like AVL or RB-tree, in case you want strict O(logN) performance)
For intervals [a-b]
Build the tree keeping ‘a’ as the key.
Node structure would be something like:
In order to search: