离散数学课件 第七章 树trees

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第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

层次level

v0的层次为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个子女。定义4

A 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 which

every 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 the

number 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 set

of 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-249

18,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.1

1)n个节点的定位二叉树有多少个?

2)如何枚举?

定位二叉树的计算机表示

Computer Representation of Binary Positional Trees

2

3

4

5

6

7

8

9

10

11

12

13

14

Homework PP253-254

10,11,12,16,18,

§7.3 树的遍历tree searching(自学)二叉树的遍历

中序遍历的递归算法定义

(1)遍历左子树;

(2)访问根结点;

(3)遍历右子树。

先序遍历的递归算法定义

(1) 访问根结点;

(2) 遍历左子树;

(3) 遍历右子树。

后序遍历得递归算法定义

(1)遍历左子树;

(2)遍历右子树;

(3)访问根结点

树的搜索

深度优先搜索

广度优先搜索

启发式搜索

博弈树搜索

§7.4无向树undirected trees

无向图连通不含回路的图叫无向树例

相关文档
最新文档