血糖偏高吃什么水果好| 糗大了是什么意思| 孕妇感冒可以吃什么感冒药| 指滑是什么意思| 百合是什么颜色| 凝血四项是查什么的| 尿检阳性是什么意思| 梦见和老公结婚是什么意思| 怀孕日期是从什么时候开始算| 希腊用什么货币| 扁桃体发炎吃什么水果| 益母草长什么样子图片| 94年属狗什么命| 一什么对联| 忻字五行属什么| 常温保存是什么意思| 叶酸片有什么功效| 暖手宝里面是什么| 鸡爪煲汤放什么材料| bug是什么意思网络用语| 助力油是什么油| 印度信仰什么教| 我追呀追呀是什么歌曲| 蛋白尿吃什么食物好| 焦虑症吃什么好| 宫颈ca什么意思| 雅漾属于什么档次| gas什么意思| 女人的排卵期一般是什么时候| 一点是什么时辰| 4.8什么星座| 健康管理师是干什么的| 风花雪月下一句是什么| 93年属相是什么| 左心室高电压是什么意思| 宋徽宗叫什么| 有福气是什么意思| 为什么月经前乳房胀痛| shark是什么意思| 网调是什么意思| 鼻窦炎都有什么症状| 捆绑是什么意思| 心梗吃什么药| 珠联璧合是什么意思| 两情相悦什么意思| 窜稀吃什么药| 枕头太低了有什么危害| 什么是体制内的工作| 六月十五号是什么星座| 倒三角是什么意思| 冰晶是什么东西| ncs是什么意思| 什么东西好消化| 虚岁24岁属什么生肖| 尿蛋白阴性是什么意思| 猫咪取什么名字好听| 专车是什么意思| cook是什么意思| 眼睛痒用什么眼药水好| 肋骨外翻挂什么科| 飞黄腾达是什么生肖| 大闸蟹什么时候吃| 藏红花什么时候喝最好| 蝙蝠属于什么类| aa是什么| gd是什么意思| 血红蛋白浓度偏高是什么原因| 客单价什么意思| 春天开什么花| 呼吸衰竭是什么意思| 蚂蝗长什么样| 蜂蜜水什么时间喝最好| snoopy是什么意思| 撕票是什么意思| 肚子大挂什么科| 右侧上颌窦粘膜增厚是什么意思| 三妻四妾是什么意思| 钾高是什么原因造成的| 滑板什么意思| 大红袍属于什么茶| 这个表情是什么意思| 湿疹有什么忌口的食物| 孕酮起什么作用| 心有灵犀是什么意思| 什么叫电解质| 感冒嗓子痒咳嗽吃什么药| dazzling什么意思| 男人为什么喜欢大胸| 前列腺增生用什么药| 牛属相和什么属相配| 吃什么水果减肥最快减肚子| 冯庸大学现在叫什么| 青蛙喜欢吃什么| Zucchini是什么意思| 广西三月三是什么节日| 什么是白带| 乳腺疼挂什么科| 美国为什么要打伊朗| 荨麻疹不能吃什么食物| 1996属鼠的是什么命| 夹腿是什么意思| 粘鞋子用什么胶水最好| r商标是什么意思| 皮下水肿是什么原因| 吃什么不会胖| 乳头凹陷是什么原因| 现在流行什么样的衣柜| 贫血到什么程度会晕倒| 青城之恋是什么生肖| 三月三是什么星座| 疑心病是什么意思| 夏天白鸽煲什么汤最好| 甲功七项能查出什么病| 脸上长癣是什么原因造成的| 清洁度二度是什么意思| 夏天补什么| 甘油三酯高是什么原因造成的| 做梦杀人了是什么征兆| 菠菜什么季节吃| 总打嗝吃什么药| 狂风暴雨是什么生肖| 茶寿为什么是108岁| 瘦了是什么原因| 私奔什么意思| 手麻挂什么科| 尿素偏高是什么意思| 脸上老长痘痘是什么原因| 属狗的什么命| 咖啡加奶叫什么| 前胸后背出汗多是什么原因| 办理护照需要什么材料| 山东日照有什么好玩的| 藿香泡水喝有什么好处| 黄疸高对婴儿有什么影响| 吃什么减肥最好最快| 辟谷期间可以吃什么| 什么食物降血脂| 嘴唇干燥是什么原因引起的| 荔枝都有什么品种| 口大是什么字| 属兔什么命| 虹膜是什么意思| 草龟吃什么| kps是什么意思| 大便青黑色是什么原因| 上睑下垂是什么原因造成的| 三点水加四读什么| 人吸了甲醛有什么症状| 什么动物睡觉不闭眼| 洋葱对肝脏有什么好处| 王不见王是什么意思| 两个人可以玩什么游戏| 龟是什么结构| 安宫牛黄丸为什么那么贵| 2月11日什么星座| 出汗多是什么病| 早晨起床手麻是什么原因| 1988年是什么生肖| 心肾不交吃什么中成药| 梦见捡硬币是什么预兆| 耳鸣吃什么药最有效| 皮脂腺囊肿看什么科| 糖耐主要是检查什么| 收放自如是什么意思| 奥美拉唑与雷贝拉唑有什么区别| 紫癜有什么危害| 什么是扁平足| 尿蛋白高是什么原因| 为什么会得阴道炎| QQ什么意思| 老酒是什么酒| 大豆是指什么豆| 福肖指什么生肖| 维纳斯是什么意思| 来月经是黑色的是什么原因| 眼睛发黄是什么原因| 梦到自己孩子死了是什么征兆| 男人做梦梦到蛇是什么意思| 哑巴是什么原因造成的| 中央电视台台长是什么级别| 两个禾念什么| 接盘是什么意思| 低血糖是什么引起的| cm代表什么单位| 手脚发麻是什么原因引起的| 包裹是什么意思| 孕妇做糖筛是检查什么| 猪肚炖什么| 棱长是什么意思| 医院属于什么行业| fwb是什么意思| 合成碳硅石是什么| 怀女儿有什么症状| 慎独什么意思| 梦见洗碗是什么预兆| 属兔本命佛是什么佛| 什么感觉| 柠檬有什么作用| 花心是什么意思| 男人吃秋葵有什么好处| 有始无终是什么生肖| 奇行种什么意思| 秋天开什么花| 什么汤补气血效果最好| 鼻子旁边有痣代表什么| 低热吃什么药| 六艺是什么| 1993属什么生肖| 气管痉挛是什么症状| 28.88红包代表什么意思| 黄芪最佳搭配是什么| 经常掉头发是什么原因| 生不逢时是什么意思| 五行中金代表什么| 吃什么好排大便| 运动后出汗多是什么原因| 小手指麻木是什么原因| 我国四大发明是什么| 女人戴黄金有什么好处| 白是什么结构的字| 12月13日是什么日子| 皮蛋是什么蛋做的| 解表化湿是什么意思| 女人喝红酒有什么好处| 冰枕对人有什么危害吗| 志字五行属什么| 小腿发凉是什么原因造成的| 在什么情况下最容易怀孕| 花都有什么花| 三生万物是什么意思| 黄辣丁吃什么食物| 西瓜适合什么土壤种植| 深水炸弹什么意思| 阴道没水什么原因| 印度神油是什么东西| 怀孕送什么礼物| 丹字五行属什么| 画饼充饥是什么意思| 腰椎膨出是什么意思| 痔瘘和痔疮有什么区别| 舞美是什么| 血脂高有什么危害| 腰间盘突出吃什么药好| 突然视力模糊是什么原因引起的| 孕妇吃什么鱼| 下葬下雨是什么兆头| 什么一现| 青黛是什么意思| 深红色是什么颜色| 1979年属什么生肖| 冬虫夏草有什么用| 变化无常的意思是什么| 胺试验阳性是什么意思| 尿酸碱度是什么意思| 免职和撤职有什么区别| 头不由自主的轻微晃动是什么病| 什么是活珠子| 胃不好应该吃什么| 吃什么可以拉肚子通便| 黑色素瘤是什么| ana医学上是什么意思| 乙肝有抗体是显示什么结果| 牛头马面指什么生肖| 金国人是现在的什么人| 百度

送女生什么生日礼物比较好

(Redirected from Tree (data structure))
百度   汪洋指出,长期以来,各民主党派始终同中国共产党肝胆相照、荣辱与共,为我国革命、建设和改革事业作出了重要贡献。

In computer science, a tree is a widely used abstract data type that represents a hierarchical tree structure with a set of connected nodes. Each node in the tree can be connected to many children (depending on the type of tree), but must be connected to exactly one parent,[1][2] except for the root node, which has no parent (i.e., the root node as the top-most node in the tree hierarchy). These constraints mean there are no cycles or "loops" (no node can be its own ancestor), and also that each child can be treated like the root node of its own subtree, making recursion a useful technique for tree traversal. In contrast to linear data structures, many trees cannot be represented by relationships between neighboring nodes (parent and children nodes of a node under consideration, if they exist) in a single straight line (called edge or link between two adjacent nodes).

This unsorted tree has non-unique values (e.g., the value 2 existing in different nodes, not in a single node only) and is non-binary (while there are only up to two children nodes per parent node in a binary tree). The root node at the top (with the value 2 here), has no parent as it is the highest in the tree hierarchy.

Binary trees are a commonly used type, which constrain the number of children for each parent to at most two. When the order of the children is specified, this data structure corresponds to an ordered tree in graph theory. A value or pointer to other data may be associated with every node in the tree, or sometimes only with the leaf nodes, which have no children nodes.

The abstract data type (ADT) can be represented in a number of ways, including a list of parents with pointers to children, a list of children with pointers to parents, or a list of nodes and a separate list of parent-child relations (a specific type of adjacency list). Representations might also be more complicated, for example using indexes or ancestor lists for performance.

Trees as used in computing are similar to but can be different from mathematical constructs of trees in graph theory, trees in set theory, and trees in descriptive set theory.

Terminology

edit

A node is a structure which may contain data and connections to other nodes, sometimes called edges or links. Each node in a tree has zero or more child nodes, which are below it in the tree (by convention, trees are drawn with descendants going downwards). A node that has a child is called the child's parent node (or superior). All nodes have exactly one parent, except the topmost root node, which has none. A node might have many ancestor nodes, such as the parent's parent. Child nodes with the same parent are sibling nodes. Typically siblings have an order, with the first one conventionally drawn on the left. Some definitions allow a tree to have no nodes at all, in which case it is called empty.

An internal node (also known as an inner node, inode for short, or branch node) is any node of a tree that has child nodes. Similarly, an external node (also known as an outer node, leaf node, or terminal node) is any node that does not have child nodes.

The height of a node is the length of the longest downward path to a leaf from that node. The height of the root is the height of the tree. The depth of a node is the length of the path to its root (i.e., its root path). Thus the root node has depth zero, leaf nodes have height zero, and a tree with only a single node (hence both a root and leaf) has depth and height zero. Conventionally, an empty tree (tree with no nodes, if such are allowed) has height ?1.

Each non-root node can be treated as the root node of its own subtree, which includes that node and all its descendants.[a][3]

Other terms used with trees:

Neighbor
Parent or child.
Ancestor
A node reachable by repeated proceeding from child to parent.
Descendant
A node reachable by repeated proceeding from parent to child. Also known as subchild.
Degree
For a given node, its number of children. A leaf, by definition, has degree zero.
Degree of tree
The degree of a tree is the maximum degree of a node in the tree.
Distance
The number of edges along the shortest path between two nodes.
Level
The level of a node is the number of edges along the unique path between it and the root node.[4] This is the same as depth.
Width
The number of nodes in a level.
Breadth
The number of leaves.
Complete tree
A tree with every level filled, except the last.
Forest
A set of one or more disjoint trees.
Ordered tree
A rooted tree in which an ordering is specified for the children of each vertex.
Size of a tree
Number of nodes in the tree.

Common operations

edit
  • Enumerating all the items
  • Enumerating a section of a tree
  • Searching for an item
  • Adding a new item at a certain position on the tree
  • Deleting an item
  • Pruning: Removing a whole section of a tree
  • Grafting: Adding a whole section to a tree
  • Finding the root for any node
  • Finding the lowest common ancestor of two nodes

Traversal and search methods

edit

Stepping through the items of a tree, by means of the connections between parents and children, is called walking the tree, and the action is a walk of the tree. Often, an operation might be performed when a pointer arrives at a particular node. A walk in which each parent node is traversed before its children is called a pre-order walk; a walk in which the children are traversed before their respective parents are traversed is called a post-order walk; a walk in which a node's left subtree, then the node itself, and finally its right subtree are traversed is called an in-order traversal. (This last scenario, referring to exactly two subtrees, a left subtree and a right subtree, assumes specifically a binary tree.) A level-order walk effectively performs a breadth-first search over the entirety of a tree; nodes are traversed level by level, where the root node is visited first, followed by its direct child nodes and their siblings, followed by its grandchild nodes and their siblings, etc., until all nodes in the tree have been traversed.

Representations

edit

There are many different ways to represent trees. In working memory, nodes are typically dynamically allocated records with pointers to their children, their parents, or both, as well as any associated data. If of a fixed size, the nodes might be stored in a list. Nodes and relationships between nodes might be stored in a separate special type of adjacency list. In relational databases, nodes are typically represented as table rows, with indexed row IDs facilitating pointers between parents and children.

Nodes can also be stored as items in an array, with relationships between them determined by their positions in the array (as in a binary heap).

A binary tree can be implemented as a list of lists: the head of a list (the value of the first term) is the left child (subtree), while the tail (the list of second and subsequent terms) is the right child (subtree). This can be modified to allow values as well, as in Lisp S-expressions, where the head (value of first term) is the value of the node, the head of the tail (value of second term) is the left child, and the tail of the tail (list of third and subsequent terms) is the right child.

Ordered trees can be naturally encoded by finite sequences, for example with natural numbers.[5]

Examples of trees and non-trees

edit
Not a tree: two non-connected parts, A→B and C→D→E. There is more than one root.
Not a tree: undirected cycle 1-2-4-3. 4 has more than one parent (inbound edge).
Not a tree: cycle B→C→E→D→B. B has more than one parent (inbound edge).
Not a tree: cycle A→A. A is the root but it also has a parent.
Each linear list is trivially a tree.

Type theory

edit

As an abstract data type, the abstract tree type T with values of some type E is defined, using the abstract forest type F (list of trees), by the functions:

value: TE
children: TF
nil: () → F
node: E × FT

with the axioms:

value(node(e, f)) = e
children(node(e, f)) = f

In terms of type theory, a tree is an inductive type defined by the constructors nil (empty forest) and node (tree with root node with given value and children).

Mathematical terminology

edit

Viewed as a whole, a tree data structure is an ordered tree, generally with values attached to each node. Concretely, it is (if required to be non-empty):

  • A rooted tree with the "away from root" direction (a more narrow term is an "arborescence"), meaning:
    • A directed graph,
    • whose underlying undirected graph is a tree (any two vertices are connected by exactly one simple path),[6]
    • with a distinguished root (one vertex is designated as the root),
    • which determines the direction on the edges (arrows point away from the root; given an edge, the node that the edge points from is called the parent and the node that the edge points to is called the child), together with:
  • an ordering on the child nodes of a given node, and
  • a value (of some data type) at each node.

Often trees have a fixed (more properly, bounded) branching factor (outdegree), particularly always having two child nodes (possibly empty, hence at most two non-empty child nodes), hence a "binary tree".

Allowing empty trees makes some definitions simpler, some more complicated: a rooted tree must be non-empty, hence if empty trees are allowed the above definition instead becomes "an empty tree or a rooted tree such that ...". On the other hand, empty trees simplify defining fixed branching factor: with empty trees allowed, a binary tree is a tree such that every node has exactly two children, each of which is a tree (possibly empty).

Applications

edit

Trees are commonly used to represent or manipulate hierarchical data in applications such as:

Trees can be used to represent and manipulate various mathematical structures, such as:

Tree structures are often used for mapping the relationships between things, such as:

JSON and YAML documents can be thought of as trees, but are typically represented by nested lists and dictionaries.

See also

edit

Notes

edit
  1. ^ This is different from the formal definition of subtree used in graph theory, which is a subgraph that forms a tree – it need not include all descendants. For example, the root node by itself is a subtree in the graph theory sense, but not in the data structure sense (unless there are no descendants).

References

edit
  1. ^ Subero, Armstrong (2020). "3. Tree Data Structure". Codeless Data Structures and Algorithms. Berkeley, CA: Apress. doi:10.1007/978-1-4842-5725-8. ISBN?978-1-4842-5724-1. A parent can have multiple child nodes. ... However, a child node cannot have multiple parents. If a child node has multiple parents, then it is what we call a graph.
  2. ^ "Abstract Tree / Tree ADT | Abstract Data Types | ECE 250 | University of Waterloo". ece.uwaterloo.ca. Retrieved 2025-08-07.
  3. ^ Weisstein, Eric W. "Subtree". MathWorld.
  4. ^ Susanna S. Epp (Aug 2010). Discrete Mathematics with Applications. Pacific Grove, CA: Brooks/Cole Publishing Co. p.?694. ISBN?978-0-495-39132-6.
  5. ^ L. Afanasiev; P. Blackburn; I. Dimitriou; B. Gaiffe; E. Goris; M. Marx; M. de Rijke (2005). "PDL for ordered trees" (PDF). Journal of Applied Non-Classical Logics. 15 (2): 115–135. doi:10.3166/jancl.15.115-135. S2CID?1979330.
  6. ^ Levin, Oscar (31 December 2018). Discrete Mathematics: An Open Introduction (3rd?ed.). Amazon Digital Services LLC - Kdp. p.?247. ISBN?978-1792901690.

Further reading

edit
edit
肾积水吃什么药最好 语字五行属什么 什么食物含锌 77年五行属什么 尿道炎是什么原因引起的
脂肪肝有什么症状 吃什么长胎 盐洗脸有什么好处 长期失眠吃什么食物好 sco是什么意思
转注是什么意思 做梦掉牙齿是什么意思周公解梦 缺锌有什么表现和症状 苦瓜什么人不能吃 手足口疫苗什么时候打
前列腺肥大是什么症状 频发房性早搏是什么意思 五月十八什么星座 筛是什么意思 特需门诊是什么意思
曝光是什么意思hcv8jop4ns3r.cn 什么的头发520myf.com 糖尿病都有什么症状hcv8jop8ns7r.cn 曲解什么意思xinmaowt.com 直接胆红素偏高是什么原因hcv9jop1ns9r.cn
曹操是什么样的人hcv9jop4ns8r.cn 假小子是什么意思hcv7jop7ns3r.cn 8月31号是什么星座hcv7jop7ns0r.cn 三个马读什么hcv8jop8ns1r.cn 男生剪什么发型好看tiangongnft.com
磨豆腐是什么意思hcv8jop1ns0r.cn 讲信修什么hcv8jop9ns2r.cn 眉毛变白是什么原因zhiyanzhang.com 6月18是什么日子hcv9jop3ns9r.cn 六盘水为什么叫凉都hcv8jop9ns0r.cn
佛舍利到底是什么hcv9jop0ns5r.cn 大便绿色的是什么原因hkuteam.com 零和游戏是什么意思hcv8jop4ns0r.cn 36岁属什么生肖hcv9jop2ns8r.cn 入赘是什么意思hcv9jop1ns7r.cn
百度