From e8abbb5a1d428f06c1023144a71bc2196783cab2 Mon Sep 17 00:00:00 2001 From: artkpv Date: Tue, 21 Nov 2017 13:24:17 +0300 Subject: [PATCH] Ex. 14.3-3 change Not sure about the answer given as what it `res` there and what is returned. --- C14-Augmenting-Data-Structures/14.3.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) 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 ***