Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 17: Trees and Networks I Discrete Mathematical Structures: Theory and Applications.

Similar presentations


Presentation on theme: "Lecture 17: Trees and Networks I Discrete Mathematical Structures: Theory and Applications."— Presentation transcript:

1 Lecture 17: Trees and Networks I Discrete Mathematical Structures: Theory and Applications

2 Discrete Mathematical Structures: Theory and Applications 2 Learning Objectives  Learn the basic properties of trees  Explore applications of trees  Learn about networks

3 Discrete Mathematical Structures: Theory and Applications 3 Trees  Each atom of a chemical compound is represented by a point in a plane  Atomic bonds are represented by lines  Shown in Figure 11.1 for the chemical compound with the formula C 4 H 10.

4 Discrete Mathematical Structures: Theory and Applications 4 Trees  In chemistry, chemical compounds with formula C k H 2k+2 are known as paraffins, which contain k carbon atoms and 2k + 2 hydrogen atoms.  In the graphical representation, each of the carbon atoms corresponds to a vertex of degree 4 and each of the hydrogen atoms corresponds to a vertex of degree 1.  For the same chemical formula C 4 H 10, the graph shown in Figure 11.2 is also a representation.

5 Discrete Mathematical Structures: Theory and Applications 5 Trees  These graphs are connected and have no cycles. Hence, each of these graphs is a tree.

6 Discrete Mathematical Structures: Theory and Applications 6 Trees  Consider the graphs shown in Figure 11.4. Each of these graphs is connected.  However, each of these graphs has a cycle. Hence, none of these graphs is a tree.

7 Discrete Mathematical Structures: Theory and Applications 7 Trees

8 Discrete Mathematical Structures: Theory and Applications 8 Trees

9 Discrete Mathematical Structures: Theory and Applications 9 Trees

10 Discrete Mathematical Structures: Theory and Applications 10 Rooted Tree

11 Discrete Mathematical Structures: Theory and Applications 11 Rooted Tree  The level of a vertex v is the length of the path from the root to v.

12 Discrete Mathematical Structures: Theory and Applications 12

13 Discrete Mathematical Structures: Theory and Applications 13

14 Discrete Mathematical Structures: Theory and Applications 14

15 Discrete Mathematical Structures: Theory and Applications 15  The root of this binary tree is A. Vertex B is the left child of A and vertex C is the right child of A. From the diagram, it follows that B is the root of the left subtree of A, i.e., the left subtree of the root. Similarly, C is the root of the right subtree of A, i.e., the right subtree of the root. L A = {B, D, E, G} and R A = {C, F,H}. Moreover, for vertex F, the left child is H and F has no right child.

16 Discrete Mathematical Structures: Theory and Applications 16 Rooted Tree

17 Discrete Mathematical Structures: Theory and Applications 17 Rooted Tree  Binary Tree Traversal  Item insertion, deletion, and lookup operations require the binary tree to be traversed. Thus, the most common operation performed on a binary tree is to traverse the binary tree, or visit each vertex of the binary tree. The traversal must start at the root because one is typically given a reference to the root. For each vertex, there are two choices.  Visit the vertex first.  Visit the subtrees first.

18 Discrete Mathematical Structures: Theory and Applications 18 Rooted Tree  Inorder Traversal: In an inorder traversal, the binary tree is traversed as follows.  Traverse the left subtree.  Visit the vertex.  Traverse the right subtree.

19 Discrete Mathematical Structures: Theory and Applications 19 Rooted Tree  Preorder Traversal: In a preorder traversal, the binary tree is traversed as follows.  Visit the vertex.  Traverse the left subtree.  Traverse the right subtree.

20 Discrete Mathematical Structures: Theory and Applications 20 Rooted Tree  Postorder Traversal: In a postorder traversal, the binary tree is traversed as follows.  Traverse the left subtree.  Traverse the right subtree.  Visit the vertex.

21 Discrete Mathematical Structures: Theory and Applications 21 Rooted Tree  Each of these traversal algorithms is recursive.  The listing of the vertices produced by the inorder traversal of a binary tree is called the inorder sequence.  The listing of the vertices produced by the preorder traversal of a binary tree is called the preorder sequence.  The listing of the vertices produced by the postorder traversal of a binary tree is called the postorder sequence.

22 Discrete Mathematical Structures: Theory and Applications 22 Rooted Tree  Binary Search Trees  To determine whether 50 is in the binary tree, any of the previous traversal algorithms to visit each vertex and compare the search item with the data stored in the vertex can be used.  However, this could require traversal of a large part of the binary tree, so the search would be slow.  Each vertex in the binary tree must be visited until either the item is found or the entire binary tree has been traversed because no criteria exist to guide the search.

23 Discrete Mathematical Structures: Theory and Applications 23 Rooted Tree  Binary Search Trees  In the binary tree in Figure 11.22, the value of each vertex is larger than the values of the vertices in its left subtree and smaller than the values of the vertices in its right subtree.  The binary tree in Figure 11.22 is a special type of binary tree, called a binary search tree.

24 Discrete Mathematical Structures: Theory and Applications 24


Download ppt "Lecture 17: Trees and Networks I Discrete Mathematical Structures: Theory and Applications."

Similar presentations


Ads by Google