VOOZH about

URL: https://www.geeksforgeeks.org/dsa/introduction-to-li-chao-tree/

⇱ Introduction to Li Chao Tree - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Introduction to Li Chao Tree

Last Updated : 28 Apr, 2025

A Li Chao tree (also known as a Dynamic Convex Hull or Segment Tree with lazy propagations) is a data structure that allows for efficient dynamic maintenance of the convex hull of a set of points in a 2D plane. The Li Chao tree allows for dynamic insertion, deletion, and query operations on the set of points, and can be used in a variety of geometric problems such as line segment intersection, visibility graphs, and polygon triangulation.

  • The structure of a Li Chao tree is a segment tree, a balanced binary tree data structure where each leaf node represents a single point, and each internal node represents a convex hull of the points represented by its child nodes. 
  • The tree is balanced to ensure that each leaf node is at roughly the same depth, which allows for logarithmic time complexity for operations such as insertion and deletion.

To go further one should begin with some geometric utility functions as given below:


On every node of the segment tree, we are storing the line that maximizes (or minimizes) the value of the mid. If the interval of the node is [L, R), then the line stored in it will maximize(or minimize). 

Insert: Let's say we are inserting a  new line to the node which is corresponding to Interval [L, R).To make it easy let's assume that the line on the node has a smaller slope. So, mid =\ frac{L + R}{2}.  Now we have two cases to think about.

Note: Red is the original line in the node

Case 1: red(mid) < blue(mid)

In this Case, We have to replace red line with blue.Now, should we remove red?  The answer is No, because there is need of red in segment [L, mid). Because of this reason we should pass red to the node with interval [L, mid), which is its left son.

👁 Image
representation of case 1

Case 2: red(mid) > blue(mid)

In similar way, we should pass blue to its right son and keep red in this node, whose interval is [mid, R).

👁 Image
representation of case 2

Below is the code for the above approach:

Code block


Code for queries, as we know we only need to consider the intervals that contain the point we need to ask from the way we inserted lines.


Time Complexity: O(NLogN), for the construction of the tree and O(LogN) for each Query 
Auxiliary Space: O(N)

Advantages of Li Chao tree:

  • Dynamic Convex Hull: The Li Chao tree is a dynamic data structure that can handle line segments and can be used to maintain the convex hull of a set of lines in real-time.
  • Fast Queries: Li Chao tree has a logarithmic time complexity for querying the minimum value on a given line segment, making it efficient for large datasets.
  • Space-efficient: Li Chao tree uses a balanced binary tree structure, which is space-efficient.

Disadvantages of the Li Chao tree:

  • Complexity: The construction of the Li Chao tree takes O(n log n) time and O(n) space, which can be computationally expensive for large datasets.
  • Limited to lines: Li Chao tree can only handle line segments and not other types of geometric shapes.
  • Limited to 2D: Li Chao tree is limited to 2-dimensional space and cannot be used for 3D or higher-dimensional problems.
  • Limited to linear functions: Li Chao tree is limited to linear functions and cannot be used for non-linear functions.
Comment