Tree Math Discrete
Tree Math Discrete
Trees (1)
Xiaocong ZHOU
Department of Computer Science Sun Yat-sen University
May. 2013
http://www.cs.sysu.edu.cn/ zxc [email protected]
Xiaocong ZHOU (SYSU) Discrete Mathematics May. 2013 1 / 40
OUTLINE
Discrete Mathematics
May. 2013
2 / 40
Introduction to Trees
Trees
Theorem
Discrete Mathematics
May. 2013
3 / 40
Introduction to Trees
Example
Discrete Mathematics
May. 2013
4 / 40
Introduction to Trees
Forest
The graphs with the property that each of their connected is a tree are called forest()
Example
An example of forests
Discrete Mathematics
May. 2013
5 / 40
Introduction to Trees
Discrete Mathematics
May. 2013
6 / 40
Introduction to Trees
When u is the parent of v, v is called a child() of u Vertices with the same parent are called siblings() The ancestors() and descendants() of a vertex a vertex of a tree is called a leaf() if it has no children Vertex that have children are called internal vertices()
The root is an internal vertex unless it is the only vertex in the graph
If a is a vertex in a tree, the subtree() with a as its root is the subgraph of the tree consisting of
a and its descendants and all edges incident to these descendants
Xiaocong ZHOU (SYSU) Discrete Mathematics May. 2013 7 / 40
Introduction to Trees
Are the rooted trees full m-ary trees for some positive integer m?
Discrete Mathematics
May. 2013
8 / 40
Introduction to Trees
Discrete Mathematics
May. 2013
9 / 40
Trees as Models
Discrete Mathematics
May. 2013
10 / 40
Trees as Models
Discrete Mathematics
May. 2013
11 / 40
Trees as Models
Discrete Mathematics
May. 2013
12 / 40
Properties of Trees
Properties of trees
Theorem
Discrete Mathematics
May. 2013
13 / 40
Properties of Trees
Example
How many people have seen the letter, including the rst person, if
no one receives more than one letter and the chain letter ends after there have been 100 people who read it but did not send it out?
Discrete Mathematics
May. 2013
14 / 40
Properties of Trees
Discrete Mathematics
May. 2013
15 / 40
Properties of Trees
Balanced trees
Discrete Mathematics
May. 2013
16 / 40
Properties of Trees
Theorem
if an m-ary tree of height h has l leaves, then h logm l If the m-ary tree is full and balanced, then h = logm l
Recall that x is the smallest integer grater than or equal to x
Discrete Mathematics
May. 2013
17 / 40
Traversal Algorithms
Traversal algorithms
Procedures for systematically visting every vertex of an ordered rooted tree are called traversal algorithms()
preorder traversal() inorder traversal() postorder traversal()
Discrete Mathematics
May. 2013
18 / 40
Traversal Algorithms
Preorder traversal
Discrete Mathematics
May. 2013
19 / 40
Traversal Algorithms
Preorder traversal
Discrete Mathematics
May. 2013
20 / 40
Traversal Algorithms
Preorder traversal
Example
In which order does a preorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
21 / 40
Traversal Algorithms
Preorder traversal
Example
In which order does a preorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
21 / 40
Traversal Algorithms
Preorder traversal
Example
In which order does a preorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
21 / 40
Traversal Algorithms
Preorder traversal
Example
In which order does a preorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
21 / 40
Traversal Algorithms
Preorder traversal
Example
In which order does a preorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
21 / 40
Traversal Algorithms
Preorder traversal
Discrete Mathematics
May. 2013
22 / 40
Traversal Algorithms
Inorder traversal
Discrete Mathematics
May. 2013
23 / 40
Traversal Algorithms
Inorder traversal
Discrete Mathematics
May. 2013
24 / 40
Traversal Algorithms
Inorder traversal
Example
In which order does a inorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
25 / 40
Traversal Algorithms
Inorder traversal
Example
In which order does a inorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
25 / 40
Traversal Algorithms
Inorder traversal
Example
In which order does a inorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
25 / 40
Traversal Algorithms
Inorder traversal
Example
In which order does a inorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
25 / 40
Traversal Algorithms
Inorder traversal
Example
In which order does a inorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
25 / 40
Traversal Algorithms
Traversal Algorithms
Postorder traversal
Discrete Mathematics
May. 2013
27 / 40
Traversal Algorithms
Postorder traversal
Discrete Mathematics
May. 2013
28 / 40
Traversal Algorithms
Postorder traversal
Example
In which order does a postorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
29 / 40
Traversal Algorithms
Postorder traversal
Example
In which order does a postorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
29 / 40
Traversal Algorithms
Postorder traversal
Example
In which order does a postorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
29 / 40
Traversal Algorithms
Postorder traversal
Example
In which order does a postorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
29 / 40
Traversal Algorithms
Postorder traversal
Example
In which order does a postorder traversal visit the vertices in the ordered root tree T ?
Discrete Mathematics
May. 2013
29 / 40
Traversal Algorithms
Postorder traversal
Discrete Mathematics
May. 2013
30 / 40
Traversal Algorithms
Discrete Mathematics
May. 2013
31 / 40
Traversal Algorithms
Example
Discrete Mathematics
May. 2013
32 / 40
Traversal Algorithms
Inx form
The fully parenthesized expression obtained in this way is said to be in inx form()
Discrete Mathematics
May. 2013
33 / 40
Traversal Algorithms
Prex form
Discrete Mathematics
May. 2013
34 / 40
Traversal Algorithms
Prex form
Discrete Mathematics
May. 2013
35 / 40
Traversal Algorithms
Prex form
Example
Discrete Mathematics
May. 2013
36 / 40
Traversal Algorithms
Postx form
Discrete Mathematics
May. 2013
37 / 40
Traversal Algorithms
Postx form
In the postx form of an expression, a binary operator follows its two operands
So, to evaluate an expression from its postx form, work from left to right
carrying out operations whenever an operator follows two operands
After an operation is carried out, the result of this operation becomes a new operand
Discrete Mathematics
May. 2013
38 / 40
Traversal Algorithms
Postx form
Example
Discrete Mathematics
May. 2013
39 / 40
Traversal Algorithms
Assignment: Exercises after 11.1, No. 4, 6, 16, 22, and Exercises after 11.3, No. 8, 11, 14, 16 Further reading: the section Universal Address Systems
Discrete Mathematics
May. 2013
40 / 40