tut2 - Tutorial 2 Augmenting data structures Problem...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Tutorial 2 Augmenting data structures Problem 14.3-4 (317): Given an interval tree, list all intervals that overlap a query interval in time O (min( n,k log n )) , where k is the number of answers. Solution: If we don’t mind changing the tree, then find and remove overlapping intervals one by one. Thereafter insert them again. This takes O (( k + 1) log n ) time (it takes O (log n ) with no overlapping intervals). Stop when k = n/ log n , since the problem is trivially solved in O ( n ) time by examining all intervals. If we don’t want to alter the tree structure, then modify INTERVAL-SEARCH in Lecture 3 to look for an overlapping interval that has the minimum low endpoint: MIN-INTERVAL-OVERLAP( T,i ) x root [ T ] while x negationslash = NIL do if left [ x ] negationslash = NIL and max [ left [ x ]] low [ i ] then x left [ x ] else if i overlaps int [ x ] then return x x right [ x ] return NIL We use this algorithm repeatedly, but will not actually delete overlapping intervals. Note that a node’s presence is felt by MIN-INTERVAL-OVERLAP only if the high endpoint of that interval affects the max of its parents (and ancestors). For this purpose, we maintain two stacks A and B of nodes. As we proceed from the root to an overlapping interval with minimum endpoint, we push the nodes (i.e. intervals) along the path onto A . After finding the overlapping interval with minimum endpoint, we trace back the route to the root. While doing so, we pop the nodes from A and push them onto B , modifying their max so that on reading the max of the ancestors of the minimum overlapping interval, we do not perceive the presence of this interval. Thus, after doing so, if we run MIN-INTERVAL-OVERLAP to find the next overlapping interval reading the nodes from stack B if they occur in it, then the algorithm computes as if the first overlapping interval were absent in the node and hence finds the next overlapping interval. We continue this process until all overlapping intervals are found (i.e. until MIN-INTERVAL- OVERLAP returns NIL).
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern