Lecture 17: Trees and Networks I - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Lecture 17: Trees and Networks I

Description:

Trees. Each atom of a chemical compound is represented by a point in a plane ... Trees ... Binary Search Trees ... – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 25
Provided by: jeffhed
Learn more at: http://cs.iupui.edu
Category:

less

Transcript and Presenter's Notes

Title: Lecture 17: Trees and Networks I


1
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

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.

4
Trees
  • In chemistry, chemical compounds with formula
    CkH2k2 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.

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

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
Trees
8
Trees
9
Trees
10
Rooted Tree
11
Rooted Tree
  • The level of a vertex v is the length of the path
    from the root to v.

12
(No Transcript)
13
(No Transcript)
14
(No Transcript)
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.

16
Rooted Tree
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
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
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
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
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
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
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
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com