Skip to main content
. 2019 Mar 25;9:5059. doi: 10.1038/s41598-019-41451-3

Table 3.

The algorithm to execute interval query using range tree with fractional cascading. Input T is the range tree; I is the query interval; R is the relationship. Return the result interval set S corresponding to all the intervals in range tree T satisfying the relationship R with interval I.

Algorithm QueryRTFC(T, I, R)
1. Transform interval query with respect to interval I and relationship R to range query with x range [x1, x2] and y range [y1, y2] according to Table 1.
2. Initialize the result set S = {}
3. Find the split node vsplit in range tree T where the paths to x1 and x2 split, or the leaf where both paths end.
4. if vsplit is a leaf node then
5.     if vsplit. interval. x ∈ [x1, x2] and vsplit. interval. y ∈ [y1, y2] then
6.         Report the interval in vsplit, S = S ∪ {vsplit. interval}
7.     end if
8. return S
9. Perform binary search on vsplit. data for y1 by y-value, find the index i of the smallest element no less than y1 in vsplit. data.
10. vsplit = vsplit. lchild, i = vsplit. lfc[i]
11. while v is not a leaf and i ≠ 1 do
12.     if x1 ≤ v. x then
13.         j = v. rfc[i]
14.         while j ≠ −1 and v rchild. data[j]. y ≤ y2 and j ≤ v. rchild. data.size do
15.             Report interval, S = S ∪ {v. rchild. data[j]}
16.             j = j + 1
17.         end while
18.         i = v. lfc[i], v = v. lchild
19.     else
20.        i = v. rfc[i], v = v. rchild
21.     end if
22. end while
23. if v is a leaf and v. interval. x ∈ [x1, x2] and v. interval. y ∈ [y1, y2] then
24.         Report the interval in v, S = S ∪ {v. interval}
25. end if
26.. v = vsplit. rchild, i = vsplit. rcf[i]
27. while v is not a leaf and i ≠ −1 do
28.     if x2 ≥ v. x then
29.         j = v. lfc[i]
30.         while j ≠ −1 and v. lchild. data[j]. y ≤ y2 and j ≤ v. lchild. data. size do
31.             Report interval, S = S ∪ {v. lchild. data[j]}
32.             j = j + 1
33.         end while
34.         i = v. rfc[i], v = v. rchild
35.     else
36.        i = v. lfc[i], v = v. lchild
37.     end if
38. end while
39. if v is a leaf and v. interval. x ∈ [x1, x2] and v. interval. y ∈ [y1, y2] then
40.         Report the interval in v, S = S ∪ {v. interval}
41. end if
42. return S