离散数学课件(英文版)-Trees_第1页
离散数学课件(英文版)-Trees_第2页
离散数学课件(英文版)-Trees_第3页
离散数学课件(英文版)-Trees_第4页
离散数学课件(英文版)-Trees_第5页
已阅读5页,还剩28页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Trees Lecture 8Discrete Mathematical StructuresRooted TreeLet A be a set, and let T be a relation on A. T is a rooted tree if there is a vertex v0 in A with the property that there exists a unique path in T from v0 to every other vertex in A, but no path from v0 to v0.v0Properties of Rooted TreeLet

2、(T, v0) be a rooted tree. Then(a) There are no cycles in T.(b) v0 is the only root of T.(c) Each vertex other than the root has in-degree one, and the root has in-degree 0v0vpcMore than one path from v0 to v.(a)v0v0A cycle from v0 to v0(b)v0vkw1?More path to w1?(c)Drawing a Rooted Tree by LevelsRoot

3、Inner nodeBranching nodeLeafLevel 0Level 1Level 2Level 3Height=3Rooted Tree and Family RelationsIt is easy to describe the family relations,and on the other hand, terms about family relations are used in rooted trees.JohnJohns childJohns parentJohns ancestorsJohns descendantsJohns siblingsSome Terms

4、 about Rooted TreeOrdered tree: the ordering is assumed on vertices in each level;n-tree: every vertex has at most n offspring;Complete n-tree: every vertes, other than leaves, has exactly n offspringBinary tree: 2-treeSubtree of a Rooted TreeIf (T,v0) is a rooted tree and vT. Let T(v) be the set of

5、 v and all its descendants, then T(v) and all edges with their two ends in T(v) is a tree, with v as its root.(It is called a subtree of (T,v0) )Proof:There is a path from v to any other vertex in T(v) since they are all the descendants of v;There cannot be more than one path from v to any other ver

6、tex w in T(v) , otherwise, in (T,v0), there are more than one path from v0 to w, both through vThere cannot be any cycle in T(v), since any cycle in T(v) is also in (T,v0)Subtrees of Binary TreeIn a ordered binary tree, a subtree is a left subtree or a right subtree. Even if a vertex has only one of

7、fspring, its subtree can be identified as left or right by its location in the digraph.Left subtreeRight subtreeLabeled Tree: an ExampleUsing rooted tree to represent a arithmetic expressions: branching vertices corresponding operatorsleaves corresponding operandsjiagbcdefh/+*+- Example: (a*(b+c)+d*

8、(e*f)/(g+(h-i)*j)Positional Trees222233333111LLLLLLLLRRRRRRRRPositional Binary TreeOrdered Binary TreeAny ordered tree can be converted into a ordered binary tree.123456789101112123456789101112Computer RepresentationS+-32x-2+xx3(3-(2x)+(x-2)-(3+x) as a doubly linked list12456791283111014133 arrays:L

9、EFT DATA RIGHTTree Searching Tree recursive algorithm to search all vertices:Inorder: left, root, righth, d, i, b, e, a, f, c, gPreorder: root, left, righta, b, d, h, i, e, c, f, gPost order: left, right, rooth, i, d, e, b, f, g, c, agfeihcabdReverse Polish NotationExample: (a*(b+c)+d*(e*f)/(g+(h-i)

10、*j)Searching in postorder: abc+*def*+ghi-j*+/It is called reverse Polish notationjiagbcdefh/+*+-No parenthesis are needed!Undirected TreeAn undirected tree is the symmetric closure of a tree.An undirected tree is represented by its graph, which has a single line without arrows connecting vertices a

11、and b.The set a,b, where (a,b) and (b,a) are in T, is called an undirected edge, and a and b are called adjacent vertices. Undirected Tree: ExamplesDifferent undirected trees with six vertices: Symmetric closurePath and Cycle in a TreeLet p: v1,v2,.,vn be path in a symmetric relation R, then p is si

12、mple if no two edges of p correspond to the same undirected edge. In above, if v1 is equal to vn , then p is a simple cycle.A symmetric relation R is acyclic if it contains no simple cycles.A symmetric relation R is connected if there is a path in R from any vertex to any other vertex. Properties of

13、 an Undirected TreeLet R be a symmetric relation on a set A. R is an undirected tree if and only if R is connected and acyclic.Proof: Let R is the symmetric closure of some tree T. Suppose that R has a simple cycle p: v1,v2,.,vn, v1. Then there is a figure of edges as the following in T. However, al

14、l possible orientation of the edges results a cycle in T. Note: the following orientation is impossible in a tree:Unique Path If T is an undirected tree, then for any vertices u, v, there is a unique uv-path in T. Proof: We know that T is connected, so, there is at least one uv-path in T. Suppose th

15、at there are two different uv-paths P,Q in T. Without loss of generality, there exists an edge e=(x,y) satisfying eP, and x is nearer to u on P than y, but eQ. Let T*=T-e, then T* contains Q. Note that xu-segment on P +Q+vy-segment on P is an xy-path in T*. However, this path plus e is a cycle in T.

16、 Contradiction. No Edge Can Be RemovedLet T is an undirected tree, e is any edge in T, then T-e is no longer connected.Proof: We have know that for any vertices v,w, there is a unique vw-path. Let e=(x,y), then e is the unique path between x and y. So, there is no xy-path in T-e, which means that T-

17、e is no longer connected.Adding One Edge Means Cycle Let T is an undirected tree, u,v are two vertices not adjecent to each other, then T+(u,v) must contain a cycle.Proof: Since T is a undirected tree, there must be a uv-path in T. Let it be P, then P+(u,v) is a cycle in T+(u,v).In fact, we can prov

18、e that there is only one cycle in T+(u,v).Number of Vertices and EdgesA tree with n vertices has n-1 edgesProof:There are at least n-1 edges to connect n vertices.Suppose that there are more than n-1 edges. So, the sum of in-degree of all vertices must be more than n-1. However, the in-degree of the

19、 root is zero, and in-degree of any of the other n-1 vertices is 1, which mean the sum is n-1. Contradiction.Spanning TreeIf R is a symmetric, connected relation on A, a tree T on A is a spanning tree of R if T is a tree with exactly the same vertices as R.An undirected spanning tree is the symmetri

20、c closure of a spanning tree.Note that an undirected spanning tree can always obtained by remove some edges from a symmetric, connected relation R.Spanning Tree: ExamplesDifferent spanning tree are obtained from a symmetric, connected relation: Breaking cyclesBreadth firstDepth first123456789101112M

21、erging Two Verticesv0v6v2v5v4v1v3v6v2v5v4v3v0v6v5v4v3v0”Matrix Operation for Mergingv0 v1 v2 v3 v4 v5 v6 v0 v1 v2 v3 v4 v5 v6 Merging v0 and v1v0” v3 v4 v5 v6 v0” v3 v4 v5 v6 v0 v2 v3 v4 v5 v6 v0 v2 v3 v4 v5 v6 Merging v0 and v2Constructing a Spanning Treeabcdaaabbbcccddd0. Let a be the starting ver

22、tex, selecting edges one by one in original R1. Merging a and c into a(a,c), selecting (a,c)2. Merging a and b into a”(a,c,b), selecting (c,b)3. Merging a” and d into a”(a,c,b,d), selecting (a,d) or (d,b)Ending, as only one vertex left(0)(1)(2)(3)Weighted Graph and MSTA weighted graph272642212153253

23、328361817342922AIHJECBGFD162125The nearest neighbor of vertex I is HThe nearest neighbor of shaded subset of vertex is GWeighted Graph and MST272642212153253328361817342922AIHJECBGFD16272642212153253328361817342922AIHJECBGFD16272642212153253328361817342922AIHJECBGFD16212121252525A Spanning Tree: W(T)=257A MST: W(T)=190Algorithms for Minimal Spanning TreeGreedy algorithms for minimal spanning treeInput: a sym

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论