Skip to main content
edited tags
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481
Make the description a description.
Source Link
rolfl
  • 98.2k
  • 17
  • 220
  • 419
  • intervals are added to a binary tree with the start of interval as index to sort on.

  • when intervals are added the maximum values of all parent nodes are updated to ensure they are in sync.

  • to check for overlap it performs a descending scan of the tree using iteration, not recursion. It checks each node it descends to, and if the node:

    1. intersects the input arguments, it returns true.
    2. if (leftsubtree != null && leftsubtree.max > low) search left
    3. else search right
  • Note, ranges only overlap if the ranges do more than just touch. The range [10,20] does not overlap with the range [20,30].

  • intervals are added to a binary tree with the start of interval as index to sort on.

  • when intervals are added the maximum values of all parent nodes are updated to ensure they are in sync.

  • to check for overlap it performs a descending scan of the tree using iteration, not recursion. It checks each node it descends to, and if the node:

    1. intersects the input arguments, it returns true.
    2. if (leftsubtree != null && leftsubtree.max > low) search left
    3. else search right
  • intervals are added to a binary tree with the start of interval as index to sort on.

  • when intervals are added the maximum values of all parent nodes are updated to ensure they are in sync.

  • to check for overlap it performs a descending scan of the tree using iteration, not recursion. It checks each node it descends to, and if the node:

    1. intersects the input arguments, it returns true.
    2. if (leftsubtree != null && leftsubtree.max > low) search left
    3. else search right
  • Note, ranges only overlap if the ranges do more than just touch. The range [10,20] does not overlap with the range [20,30].

Make the description a description.
Source Link
rolfl
  • 98.2k
  • 17
  • 220
  • 419

Implementing interval search tree. It has two API's to add anAn interval and tois a data structure that represents a range overlap ie(start & end, from & to check for overlap, or min & max, etc. To summarize algorithm). An -Interval Tree stores these intervals are added toin a binarysorted tree withstructure that makes searching for range intersections much faster. Interval trees help answer questions like: "find all stored intervals that at least partially overlap with the range a to b"

Typical interval trees store the intervals using the start of intervalthe range as indexthe key to sort ona binary search tree. To check for overlap it

This code implements the interval tree and has two methods:

  • add(start, end) - inserts an interval to the tree
  • overlap(start, end) - identifies if any interval in the tree overlaps with the input values.

The implemented algorithm follows 3 rules, which are a partan Augmented Interval Tree approach where each node maintains the maximum value contained in any of my algorithm and also commentedits child nodes. This maximum value is kept in sync by the add(start,end) method. Other details of the algorithm are:

  • intervals are added to a binary tree with the start of interval as index to sort on.

  • when intervals are added the maximum values of all parent nodes are updated to ensure they are in sync.

  • to check for overlap it performs a descending scan of the tree using iteration, not recursion. It checks each node it descends to, and if the node:

    1. intersects the input arguments, it returns true.
    2. if (leftsubtree != null && leftsubtree.max > low) search left
    3. else search right

Despite of a brief stint in explaining my problem, more details can be obtained on this link here. 

I'm looking for code review, best practices, optimizations etc. Also verifying complexity to be O(logn) O(log(n)) to add and O(logn)O(log(n)) to look for overlap. Do correct me if wrong.

Implementing interval search tree. It has two API's to add an interval and to overlap ie to check for overlap. To summarize algorithm - intervals are added to a binary tree with the start of interval as index to sort on. To check for overlap it follows 3 rules, which are a part of my algorithm and also commented. Despite of a brief stint in explaining my problem, more details can be obtained on this link here. I'm looking for code review, best practices, optimizations etc. Also verifying complexity to be O(logn) to add and O(logn) to look for overlap. Do correct me if wrong.

An interval is a data structure that represents a range (start & end, from & to, or min & max, etc.). An Interval Tree stores these intervals in a sorted tree structure that makes searching for range intersections much faster. Interval trees help answer questions like: "find all stored intervals that at least partially overlap with the range a to b"

Typical interval trees store the intervals using the start of the range as the key to a binary search tree.

This code implements the interval tree and has two methods:

  • add(start, end) - inserts an interval to the tree
  • overlap(start, end) - identifies if any interval in the tree overlaps with the input values.

The implemented algorithm follows an Augmented Interval Tree approach where each node maintains the maximum value contained in any of its child nodes. This maximum value is kept in sync by the add(start,end) method. Other details of the algorithm are:

  • intervals are added to a binary tree with the start of interval as index to sort on.

  • when intervals are added the maximum values of all parent nodes are updated to ensure they are in sync.

  • to check for overlap it performs a descending scan of the tree using iteration, not recursion. It checks each node it descends to, and if the node:

    1. intersects the input arguments, it returns true.
    2. if (leftsubtree != null && leftsubtree.max > low) search left
    3. else search right

Despite of a brief stint in explaining my problem, more details can be obtained on this link here. 

I'm looking for code review, best practices, optimizations etc. Also verifying complexity to be O(log(n)) to add and O(log(n)) to look for overlap. Do correct me if wrong.

Source Link
JavaDeveloper
  • 8.5k
  • 29
  • 93
  • 162
Loading