lecture 17: trees and networks i

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

Upload: stew

Post on 09-Feb-2016

42 views

Category:

Documents


0 download

DESCRIPTION

Lecture 17: Trees and Networks I. Discrete Mathematical Structures: Theory and Applications. Learning Objectives. Learn the basic properties of trees Explore applications of trees Learn about networks. Trees. Each atom of a chemical compound is represented by a point in a plane - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lecture 17: Trees and Networks I

Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications

Page 2: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 2

Learning Objectives

Learn the basic properties of trees

Explore applications of trees

Learn about networks

Page 3: Lecture 17: Trees and Networks I

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 C4H10.

Page 4: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 4

Trees

In chemistry, chemical compounds with formula CkH2k+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 C4H10, the graph shown in Figure 11.2 is also a representation.

Page 5: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 5

Trees

These graphs are connected and have no cycles. Hence, each of these graphs is a tree.

Page 6: Lecture 17: Trees and Networks I

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.

Page 7: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 7

Trees

Page 8: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 8

Trees

Page 9: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 9

Trees

Page 10: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 10

Rooted Tree

Page 11: Lecture 17: Trees and Networks I

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.

Page 12: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 12

Page 13: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 13

Page 14: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 14

Page 15: Lecture 17: Trees and Networks I

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. LA = {B, D, E, G} and RA = {C, F ,H}. Moreover, for vertex F , the left child is H and F has no right child.

Page 16: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 16

Rooted Tree

Page 17: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 17

Rooted Tree

Binary Tree TraversalItem 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.

Page 18: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 18

Rooted Tree

Inorder Traversal: In an inorder traversal, the binary tree is traversed as follows.

1. Traverse the left subtree.

2. Visit the vertex.

3. Traverse the right subtree.

Page 19: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 19

Rooted Tree

Preorder Traversal: In a preorder traversal, the binary tree is traversed as follows.

1. Visit the vertex.

2. Traverse the left subtree.

3. Traverse the right subtree.

Page 20: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 20

Rooted Tree

Postorder Traversal: In a postorder traversal, the binary tree is traversed as follows.

1. Traverse the left subtree.

2. Traverse the right subtree.

3. Visit the vertex.

Page 21: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 21

Rooted TreeEach 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.

Page 22: Lecture 17: Trees and Networks I

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.

Page 23: Lecture 17: Trees and Networks I

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.

Page 24: Lecture 17: Trees and Networks I

Discrete Mathematical Structures: Theory and Applications 24