离散数学课件 第七章 树trees
- 格式:doc
- 大小:867.50 KB
- 文档页数:21
离散数学树
离散数学中的树(Tree)是一种常见的图论结构,它是一种无向、连通且没有简单回路的无向图,或者是一个有向连通图,其中每个节点都只有唯一一个父节点(除了根节点)。
树形结构中的每一个节点都可以视为一个子树的根节点,因为它下面连接了若干个子节点,这样就形成了一棵向下生长的树状结构。
树形结构还有一个重要的特点就是它具有很好的递归性质,因为每个节点下面都可以再建立一棵子树,这样就可以逐层递归地构建出整棵树。
在离散数学中,树被广泛应用于算法设计、数据结构以及对计算机网络和信息系统进行建模等领域。
树的深度和广度优先遍历、树的一些基本性质(如高度、度、叶子节点等)以及树的遍历应用在图的搜索算法、排序、哈夫曼编码、抽象语法树等算法中都有广泛的应用。
第7章树trees分类§7.1 树定义1:T是集合A上一个二元关系,T称为树tree,如果存在v0∈A,任意v∈A,v≠v0,到v0都有唯一一条路径,(v0, v0) T. T叫做根树,记做(T,v0)。
A中元素称为T的顶点vertex,T中元素称为边,v0称为根root。
定理1. 设(T,v0)是树,则(a)T中没有回路。
(b)只有一个根v0。
(c)任意v∈A,v≠v0,v有入度1,v0入度是0。
证明:定义2层次levelv0的层次为0,v0的子女offspring层次为1,v0是子女的父母parent。
v i的层次为k,v i的子女offspring层次为k +1,v i是子女的父母parent,T的最大层次称为高度height。
无子女的顶点叫叶leaf。
v i的子女叫同胞sibling,同胞如有长幼,从左到右,老大,老二,老三等,组成线性序,T称为有序树,ordered tree定理2. 设(T,v0)是根树,则(a)T反自反。
(b)T反对称。
(c)(a,b)∈T,(b,c)∈T ⇒ (a,c)∉T。
定义3:n-树:每个顶点至多n个子女。
二叉树:2-树。
完全n-树:每个非叶顶点恰有n个子女。
定义4A rooted binary tree is a rooted tree in which every node has at most two children.A full binary tree (sometimes proper binary tree or 2-tree) is a tree in whichevery node other than the leaves has two children.A perfect binary tree is a full binary tree in which all leaves are at the same depth or same level.[1] (This is ambiguously also called a complete binary tree.)A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.[2]An infinite complete binary tree is a tree with levels, where for each level d thenumber of existing nodes at level d is equal to 2d. The cardinal number of the set of all nodes is . The cardinal number of the setof all paths is .A balanced binary tree is a tree where the depth of all the sub-trees differs by at most 1.定理3. 设(T,v0)是根树,v∈T,则T(v)是T的子树,T(v)的根是v。
第7章树trees分类§7.1 树定义1:T是集合A上一个二元关系,T称为树tree,如果存在v0∈A,任意v∈A,v≠v0,到v0都有唯一一条路径,(v0, v0) T. T叫做根树,记做(T,v0)。
A中元素称为T的顶点vertex,T中元素称为边,v0称为根root。
定理1. 设(T,v0)是树,则(a)T中没有回路。
(b)只有一个根v0。
(c)任意v∈A,v≠v0,v有入度1,v0入度是0。
证明:定义2层次levelv0的层次为0,v0的子女offspring层次为1,v0是子女的父母parent。
v i的层次为k,v i的子女offspring层次为k +1,v i是子女的父母parent,T的最大层次称为高度height。
无子女的顶点叫叶leaf。
v i的子女叫同胞sibling,同胞如有长幼,从左到右,老大,老二,老三等,组成线性序,T称为有序树,ordered tree定理2. 设(T,v0)是根树,则(a)T反自反。
(b)T反对称。
(c)(a,b)∈T,(b,c)∈T ⇒ (a,c)∉T。
定义3:n-树:每个顶点至多n个子女。
二叉树:2-树。
完全n-树:每个非叶顶点恰有n个子女。
定义4A rooted binary tree is a rooted tree in which every node has at most two children.A full binary tree (sometimes proper binary tree or 2-tree) is a tree in whichevery node other than the leaves has two children.A perfect binary tree is a full binary tree in which all leaves are at the same depth or same level.[1] (This is ambiguously also called a complete binary tree.)A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.[2]An infinite complete binary tree is a tree with levels, where for each level d thenumber of existing nodes at level d is equal to 2d. The cardinal number of the set of all nodes is . The cardinal number of the setof all paths is .A balanced binary tree is a tree where the depth of all the sub-trees differs by at most 1.定理3. 设(T,v0)是根树,v∈T,则T(v)是T的子树,T(v)的根是v。
Homework P248-24918,19,20,21,26,28§7.2标识树labeled trees中缀表达式central operator expression(3-2×x)+((x-2))+(3+x))定位树positional tree定义Positional n-tree is a n-tree whose vertex potentially has exactly n offspring ordered by1,2,…,n, but some of the offsprings may be missing.定位3-树每个顶点的子女都有一定位置。
定位2-树左右子树普通二叉树。
问题7.2.11)n个节点的定位二叉树有多少个?2)如何枚举?定位二叉树的计算机表示Computer Representation of Binary Positional Trees234567891011121314Homework PP253-25410,11,12,16,18,§7.3 树的遍历tree searching(自学)二叉树的遍历中序遍历的递归算法定义(1)遍历左子树;(2)访问根结点;(3)遍历右子树。
先序遍历的递归算法定义(1) 访问根结点;(2) 遍历左子树;(3) 遍历右子树。
后序遍历得递归算法定义(1)遍历左子树;(2)遍历右子树;(3)访问根结点树的搜索深度优先搜索广度优先搜索启发式搜索博弈树搜索§7.4无向树undirected trees无向图连通不含回路的图叫无向树例无向树:有向树的对称闭包。
bfgdcea定义:有向树的对称闭包。
定理1. R是对称关系。
则下列命题等价the following statement are equivalent:(TFAE)a) R是无向树。
b) R连通connected,无回路acycle。
证明:a) b)R显然连通若R有回路b)⇒a)若R连通无回路,我们可以在R上构造一棵树。
定理2. R是对称关系。
TFAER是无向树。
R无回路,每增加一条边,都产生一个新的回路。
证明:⇒ R连通,所以没加一边都有新的回路⇐若R不连通则有两个以上连通分支,所以可以加一边不产生回路R连通,去掉任意一条边都不连通。
证明:⇒若去掉一边还连通,则原图一定有回路。
⇐若原图有回路,则可以去掉一边后仍连通。
R无回路,且有n-1条边⇒对定点做归纳即可得边数为n-1⇐若原图不连通,则有k个连通分支,每支都是树,总边数为n-k。
R连通,且有n-1条边⇒⇐若原图有回路,则删掉k条边后为树,则总边数为n-1+k连通图的生成树spanning tree:定义含有所有顶点的极小连通图.存在性n个顶点连通图至少有n-1条边。
m条边的连通图去掉m-n+1条边可以得到生成树。
从连通图中如有回路,去掉回路中的一条边,继续直至没有回路,就得到生成树 唯一性最小生成树:权重最小的生成树。
带权的边:带边长的边。
带权的图:每边都带权。
Prim 算法:设 G=<V ,E>,1. U={v 0}, W=V-U, T={ }.2.11(,)arg m in{(,):,}u v w u v u U v W =∈∈U=U ∪{v 1}, W=W-{v 1}, T=T ∪{(u 1,v 1)} 3. 重复2,直至U=V . 例ABC DEF 6515562463BACDE235623931321115Kruskal 克鲁斯卡尔算法 G=(V ,E) 连通图令 T=(V ,{ }) 是G 的所有顶点而无边的非连通图。
1. 选择E 中权值最小的边,若该边连接T的两个连通分量,将它加入T,这时T的连通分量减少1;2否则选下一条权值最小的边。
3 重复1 n-1次直到T连通。
T 就是最小生成树其他相关内容介绍最快的算法The fastest minimum spanning tree algorithm to date was developed by Bernard Chazelle, which is based on the soft heap, an approximate priority queue. [1][2] Its running time is O(mα(m,n)), where m is the number of edges, n is the number of vertices and α is the classical functional inverse of the Ackermann function. The function α grows extremely slowly, so that for all practical purposes it may be considered a constant no greater than 4; thus Chazelle's algorithm takes very close to linear time.Degree-constrained spanning treeInput: n-node undirected graph G(V,E); positive integer k≤ n.Question: Does G have a spanning tree in which no node has degree greater than k?Degree-constrained spanning tree problem is NPCDirected minimum spanning treeEdmonds's algorithm O(EV) 1986, Gabow, Galil, Spencer, and Tarjan O (E + V log V ). 求从点1出发的最小树形图1) 对除1以外的每个点,选一条指向它的最小权的边。
2) 将所得到的图为G ,其对应的无向图为H 3) 若H 连通,则已经找到。
4)否则H的每个连通分支,要么是从点1出发的一个树,要么去一条边后是树(假设只有一个C)5)原图的最小树形图必然是连通分支C取一条从外部指向内部圈的边,并去掉圈内的指向该点的边。
如果不知道从那个顶点开始,则可以添加定点0,和n条权值为M的边。
HomeworkP270-271 14,18P275-276 4,8。