Discrete Mathematics
Chapter 5
Trees
7.1  Introduction
Tree
tree is a connected undirected graph thatcontains no circuits.
Recall: A circuit is a path of length >=1 that begins andends a the same vertex.
Free tree
(free) tree T is
A simple graphsuch that forevery pair ofvertices v and w
there is a uniquepath from v to w
path
Rooted tree
rooted tree is a tree
where one of its vertices is
designated the root
rootedtree
Level of a vertex and tree height
Let T be a rooted tree:
The level l(v) of a vertex v isthe length of the simple pathfrom v to the root of the tree
The height h of a rooted tree Tis the maximum of all levelnumbers of its vertices:
          h = max { l(v) }
                V(T)
Example:
 the tree on the right has height 3
rootedtree
7.2  Terminology
Parents child
Root
The only node inthe tree with noparent
Leaf
A node with nochildren
Siblings
Nodes with acommon parent
Parent of node n
The node directlyabove node n in thetree
Child of node n
A node directlybelow node n in thetree
Internal and terminal vertices
An internal vertex is avertex that has at least onechild
terminal vertex is avertex that has no children
The tree in the examplehas 4 internal vertices and4 terminal vertices
TypesVert
7.5 Binary trees
   A binary tree is a treewhere each vertex haszero, one or two children
binarytree1
Full binary tree
    A full binary tree is abinary tree in whicheach vertex has twoor no children.
fullbinary
Binary search trees
Data are associated toeach vertex
Order data alphabetically,so that for each vertex v,data to the left of v areless than data in v
and data to the right of vare greater than data in v
Example:
Number ofnodes=7
Number ofcomparison=4
Element exists
Example:
Number ofnodes=7
Number ofcomparison=3
Element exists
Example:
Key=15
Number ofnodes=7
Number ofcomparison=4
Element isn’texists
Building trees:
Another example:
Operations on trees:
1)Insert or add on tree.
2) Deletion.
7.6 Tree Traversals
1: Pre-order traversal
perfix trav
NLR
7.6 Tree Traversals
1: in-order traversal
preorder trav
LNR
More on tree traversals
3: Post-order traversal
postord trav
LRN