Segment Tree

In computer science, a Segment Tree, also known as a statistic tree, is a tree data structure used for storing information about intervals, or segments. It allows querying which of the stored segments contain a given point. It is, in principle, a static structure; that is, it’s a structure that cannot be modified once it’s built. A similar data structure is the interval tree.

A segment tree for a set I of n intervals uses O(n log n) storage and can be built in O(n log n) time. Segment trees support searching for all the intervals that contain a query point in time O(log n + k), k being the number of retrieved intervals or segments.

What is Segment Tree

What is Segment Tree

Introduction:

  1. Segment Tree meaning in DSA
  2. Introduction to Segment Trees – Data Structure and Algorithm Tutorials
  3. Persistent Segment Tree
  4. Segment tree | Efficient implementation
  5. Iterative Segment Tree
  6. Range Sum and Update in Array : Segment Tree using Stack
  7. Dynamic Segment Trees
  8. Applications, Advantages and Disadvantages of Segment Tree

Lazy Propagation:

  1. Lazy Propagation in Segment Tree
  2. Lazy Propagation in Segment Tree | Set 2
  3. Flipping Sign Problem

Range Queries:

  1. Queries to check if any non-repeating element exists within range [L, R] of an Array
  2. Range Minimum Query
  3. Querying maximum number of divisors that a number in a given range has
  4. Min-Max Range Queries in Array
  5. Range LCM Queries
  6. Number of primes in a subarray (with updates)
  7. Range query for Largest Sum Contiguous Subarray
  8. Range Queries for Longest Correct Bracket Subsequence
  9. Maximum Occurrence in a Given Range
  10. Queries to find maximum product pair in range with updates
  11. Range and Update Query for Chessboard Pieces
  12. String Range Queries to find the number of subsets equal to a given String
  13. Binary Array Range Queries to find the minimum distance between two Zeros
  14. Queries to evaluate the given equation in a range [L, R]
  15. Find element with maximum weight in given price range for Q queries

Some interesting problem on Segment Tree:

  1. Length of Longest Increasing Subsequences (LIS) using Segment Tree
  2. Maximize length of longest subarray consisting of same elements by at most K decrements
  3. Generate original permutation from given array of inversions
  4. Maximum of all subarrays of size K using Segment Tree
  5. Build a segment tree for N-ary rooted tree
  6. Length of Longest Subarray with same elements in atmost K increments
  7. Count number of increasing sub-sequences : O(NlogN)
  8. Calculate the Sum of GCD over all subarrays
  9. Cartesian tree from inorder traversal
  10. LIS using Segment Tree
  11. Reconstructing Segment Tree

Data Structure and Algorithms Course
Recent articles on Segment Tree

If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above

  • Last Updated : 26 Sep, 2023

Similar Reads