diff --git a/C14-Augmenting-Data-Structures/14.3.md b/C14-Augmenting-Data-Structures/14.3.md index 5b192b3a..95068ad9 100644 --- a/C14-Augmenting-Data-Structures/14.3.md +++ b/C14-Augmenting-Data-Structures/14.3.md @@ -28,16 +28,17 @@ Describe an efficient algorithm that, given an interval i, returns an interval o ### `Answer` - MIN-INTERVAL-SEARCH(T, i) - x <- root[T] - res <- INT_MAX - while x != nil[T] - if i overlap int[x] - res <- min(res, low[x]) - do if left[x] != nil[T] and max[left[x]] >= low[i] - then x<-left[x] - else x<-right[x] - return x + MIN-INTERVAL-SEARCH(T,i): + x = T.root + while x != T.nil: + if x.left != T.nil and i.low <= x.left.max: + x = x.left + elif x.int overlaps i: + break + else + x = x.right + return x + ### Exercises 14.3-4 ***