![Page 1: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/1.jpg)
Discrete Mathematics
Chapter 5 Trees
![Page 2: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/2.jpg)
7.1 Introduction Tree
A tree is a connected undirected graph that contains no circuits.
Recall: A circuit is a path of length >=1 that begins and ends a the same vertex.
![Page 3: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/3.jpg)
Free tree
A (free) tree T is A simple graph
such that for every pair of vertices v and w
there is a unique path from v to w
![Page 4: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/4.jpg)
Rooted tree
A rooted tree is a tree
where one of its vertices is
designated the root
![Page 5: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/5.jpg)
Level of a vertex and tree height
Let T be a rooted tree: The level l(v) of a vertex v is
the length of the simple path from v to the root of the tree
The height h of a rooted tree T is the maximum of all level numbers of its vertices:
h = max { l(v) } v V(T)
Example: the tree on the right has height 3
![Page 6: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/6.jpg)
7.2 Terminology
![Page 7: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/7.jpg)
Root The only node in
the tree with no parent
Leaf A node with no
children Siblings
Nodes with a common parent
Parent of node n The node directly
above node n in the tree
Child of node n A node directly
below node n in the tree
![Page 8: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/8.jpg)
Internal and terminal vertices
An internal vertex is a vertex that has at least one child
A terminal vertex is a vertex that has no children
The tree in the example has 4 internal vertices and 4 terminal vertices
![Page 9: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/9.jpg)
7.5 Binary trees A binary tree is a tree
where each vertex has zero, one or two children
![Page 10: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/10.jpg)
Full binary tree
A full binary tree is a binary tree in which each vertex has two or no children.
![Page 11: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/11.jpg)
Binary search trees Data are associated to
each vertex Order data alphabetically,
so that for each vertex v, data to the left of v are less than data in v
and data to the right of v are greater than data in v
![Page 12: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/12.jpg)
Example:
Number of nodes=7Number of comparison=4Element exists
![Page 13: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/13.jpg)
Example:
Number of nodes=7Number of comparison=3Element exists
![Page 14: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/14.jpg)
Example:
Key=15Number of nodes=7Number of comparison=4Element isn’t exists
![Page 15: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/15.jpg)
Building trees:
![Page 16: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/16.jpg)
Another example:
![Page 17: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/17.jpg)
Operations on trees:1)Insert or add on tree.
![Page 18: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/18.jpg)
2) Deletion.
![Page 19: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/19.jpg)
7.6 Tree Traversals
1: Pre-order traversal
NLR
![Page 20: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/20.jpg)
![Page 21: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/21.jpg)
7.6 Tree Traversals
1: in-order traversal
LNR
![Page 22: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/22.jpg)
![Page 23: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/23.jpg)
More on tree traversals 3: Post-order traversal
LRN
![Page 24: Discrete Mathematics Chapter 5 Trees. 7.1 Introduction Tree A tree is a connected undirected graph that contains no circuits. Recall: A circuit is a](https://reader035.vdocuments.us/reader035/viewer/2022062805/5697bfeb1a28abf838cb7cb1/html5/thumbnails/24.jpg)