I'm studying the implementation of interval tree, and I'm wondering if I can use a red black tree without the maximum value being stored and using the following pseudo-code?
i=input_interval
x=tree.root
while x!=None AND check_overlap(i,x)==False:
if x.left!=None AND i.high < x.low:
x=x.left
else:
x=x.right
return x
If I understand your pseudocode correctly, this wouldn't work for e.g. the following tree:
We search for
i := 41-42We get:
so we would recurse right which is wrong as the interval overlaps with the left subtree.