线段树(Segment Tree)

In computer science, a segment tree is a tree data structure for storing intervals, or segments. It allows querying which of the stored segments contain a given point. It is, in principle, a static structure; that is, its structure cannot be modified once it is built. A similar data structure is the interval tree.
A segment tree for a set I of n intervals uses O(nlogn) storage and can be built in O(nlogn) time. Segment trees support searching for all the intervals that contain a query point in O(logn+k) , k being the number of retrieved intervals or segments.
Applications of the segment tree are in the areas of computational geometry, and geographic information systems.
The segment tree can be generalized to higher dimension spaces as well.
——Wikipedia

线段树是用于存储区间的一种树状数据结构。它允许查询所存储的区间含有一个给定的点。它是一个静态数据结构,也就是说,它的结构一旦建立就不能修改(不能中途增删节点)。
一棵维护n个数据的线段树的空间复杂度为 O(nlogn) ,建树的时间复杂度为 O(nlogn) 。线段树可以在 O(logn+k) 的时间内搜索所有包含查询点的区间(k是查询区间的数目)。
有时线段树会应用于计算几何。线段树可以推广到更高维空间。
线段树作为一种常用的数据结构,有常用性,基础性和易用性等诸多特点。它的基本操作有构造线段树(建树),区间查询,单点修改,区间修改。

一、构造线段树

首先,(一维)线段树是一棵二叉树。同时,“线段”两字反映出线段树的另一个特点:每个节点表示的是一个“线段”,或者说是一个区间。一棵线段树的根节点表示的是“整体”的区间,而它的左右子树也是一棵线段树,分别表示的是这个区间的左半边和右半边。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值