【DataStructure】Description and Introduction of Tree
【Description】
At ree is a nonlinear data structure that models a hierarchical organization. The characteristic eatures are that each element may have several successors (called its “children”) and every element except one (called the “root”) has a unique predecessor (called its “parent”). Trees are common in computer science: Computer file systems are trees, the inheritance structure for Java classes is a tree, the run-time system of method invocations during the execution of a Java program is a tree, the classification of Java types is a tree, and the actual syntactical definition of the Java programming language itself forms a tree.
【Theorem】
Ø
Ø
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3hiMDg0MTkwMTExNg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
【TreesType】
Ø decision tree
A decision tree is a tree diagram that summarizes all the differents possible stages of a process that solve a problem by means of sequence of decisions. Rach internal node is a labeled with a question, each arc is laeled with an answer to its question, and each leaf node is labeled with the solution to the problem.
Five coins that appear identical are to be tested to determine which one of them is counterfeit. The only feature that distinguishes that the counterfeit coins is that it weights less than that the legitimate coins.
Ø transition diagram
A transition diagram is a tree or graphj whose internal nodes represent different states or situations that may occur during a multistage process. As in a decision tree, each leaf represents a diffenert outcome from the process. Each branch is labeled with the conditional probability that the resulting child event will occur., given that the parent event has occurred.
Ø Orredered trees
Here is the recursive definition of an ordered tree:
Anordered treeis either the empty set or a pair T= (r, S), where ris a node
andSis a sequence of disjoint ordered trees, none of which contains r.
The node ris called the rootof the tree T, and the elements of the sequence Sare its subtrees.
【Traversal Algorithms】
A traversal algorithm is a method for processing a data structure that applies a given operation to each element of the structure. For example, if the operation is to print the contents of the element, then the traversal would print every element in the structure. THe process of applying the operation to the each element is called visiting the element. So executing the traversal algorithm causes each element in the structure to be visited.There are three common algorithms for traversing a general tree.
Ø Level order traversal
Thelevel order traversalalgorithm visits the root, then visits each element on the first level,
then visits each element on the second level, and so forth, each time visiting all the elements on one level before going down to the next level. If the tree is drawn in the usual manner with its root at the top and leaves near the bottom, then the level order pattern is the same left-to-right top-to-bottom pattern that you follow to read English text.
The level order traversal of the tree shown in above figure would visit the nodes in the following order: a, b,c,d, e, f, g, h,i,j, k, l, m.
Ø The preorder traversal
The preorder traversal algorithm visits the root first and then does a preorder traversal recursively to each subtree in order.
The preorder traversalof the tree shown in above figure would visit the nodes in this order: a,b,e, h,i,f, c, d, g, j, k,l, m.
Ø The postorder traversal
The postorder traversal algorithm does a postorder traversal recursively to each subtree before visiting the root.
The postorder traversal of the tree shown in figure would visit the nodes in the following order: h,i,e,f,b,c,j,k,l,m,g,d,a
【DataStructure】Description and Introduction of Tree的更多相关文章
- 【DataStructure】Description and usage of queue
[Description] A queue is a collection that implements the first-in-first-out protocal. This means th ...
- 【BZOJ1803】Spoj1487 Query on a tree III 主席树+DFS序
[BZOJ1803]Spoj1487 Query on a tree III Description You are given a node-labeled rooted tree with n n ...
- 【LeetCode】99. Recover Binary Search Tree 解题报告(Python)
[LeetCode]99. Recover Binary Search Tree 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/p ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【BZOJ2843】极地旅行社(Link-Cut Tree)
[BZOJ2843]极地旅行社(Link-Cut Tree) 题面 BZOJ 题解 \(LCT\)模板题呀 没什么好说的了.. #include<iostream> #include< ...
- 【BZOJ4530】大融合(Link-Cut Tree)
[BZOJ4530]大融合(Link-Cut Tree) 题面 讨厌权限题!!! Loj链接 题目描述 小强要在 N个孤立的星球上建立起一套通信系统.这套通信系统就是连接 N个点的一个树.这个树的边是 ...
- 【BZOJ1969】航线规划(Link-Cut Tree)
[BZOJ1969]航线规划(Link-Cut Tree) 题面 BZOJ 题解 删边操作 套路呀 离线读入倒过来做 变成加边操作 现在考虑怎么确定两点直接的关键路径条数 如果是一棵树,那么每条边都是 ...
- 【BZOJ4825】【HNOI2017】单旋(Link-Cut Tree)
[BZOJ4825][HNOI2017]单旋(Link-Cut Tree) 题面 题面太长,懒得粘过来 题解 既然题目让你写Spaly 那就肯定不是正解 这道题目,让你求的是最大/最小值的深度 如果有 ...
- 【BZOJ3669】【Noi2014】魔法森林(Link-Cut Tree)
[BZOJ3669][Noi2014]魔法森林(Link-Cut Tree) 题面 题目描述 为了得到书法大家的真传,小 E 同学下定决心去拜访住在魔法森林中的隐 士.魔法森林可以被看成一个包含 n ...
随机推荐
- js根据银行卡号判断属于哪个银行,并返回银行缩写及银行卡类型
在做绑定银行卡,输入银行卡的时候,产品有这么一个需求,需要用户输入银行卡号的时候,显示对应的银行卡名称及简称.于是苦苦寻觅,终于找到了支付宝的开放API,银行卡校验接口 https://ccdca ...
- Hive 执行sql命令报错
Failed with exception java.io.IOException:java.lang.IllegalArgumentException: java.net.URISyntaxExce ...
- 使用python实现简单的爬虫
python爬虫的简单实现 开发环境的配置 python环境的安装 编辑器的安装 爬虫的实现 包的安装 简单爬虫的初步实现 将数据写入到数据库-简单的数据清洗-数据库的连接-数据写入到数据库 开发环境 ...
- Luogu【P1130】红牌(DP)
欧拉 本蒟蒻第一个自己想出来的DP题 请移步题目链接 调了半天.i从1到n,j从1到m. f[i][j]表示的是第i道工序在第j个小组办完所花的最短时间. 因为要用到上一个状态,而上一个状态要么是同一 ...
- BZOJ 2720 [Violet 5]列队春游 ——期望DP
很喵的一道题(我可不是因为看了YOUSIKI的题解才变成这样的) $ans=\sum_{x<=n}\sum_{i<=n} iP(L=i)$ 其中P(x)表示视线为x的概率. 所以只需要求出 ...
- 刷题总结——电影(ssoi)
题目: 题目背景 SOURCE:NOIP2014-SXYZ T2 题目描述 小美去看电影,发现这个电影票很神奇,有一个编号 (x,y) 表示为第 x 排第 y 位. 小美是个聪明的女孩子,她有自己的一 ...
- 如何将文件上传到ftp
方法1(推荐,炒鸡简单):双击我的电脑,在地址栏里输入你的ftp地址回车(比如: ftp://220.103.86.96),然后会弹出一个输入登录账号和密码的对话框,输入你的ftp账号和密码回车便进入 ...
- OI 数论整理
1.素数: 质数(prime number)又称素数,有无限个.一个大于1的自然数,除了1和它本身外,不能被其他自然数整除,换句话说就是该数除了1和它本身以外不再有其他的因数;否则称为合数. 2016 ...
- Codeforces Round #268 (Div. 2) D. Two Sets [stl - set + 暴力]
8161957 2014-10-10 06:12:37 njczy2010 D - Two Sets GNU C++ A ...
- python结构语句(while,if)
一.基础语法 编码: 默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串 #!/usr/bin/env python # -*- coding:utf- ...