ICS 241 - PowerPoint PPT Presentation

About This Presentation
Title:

ICS 241

Description:

11/1/09. 1. ICS 241. Discrete Mathematics II ... Infix/prefix/postfix notation. 11/1/09. 3. Universal Address Systems ... Infix/Prefix/Postfix Notation ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 13
Provided by: williama3
Learn more at: http://www2.hawaii.edu
Category:
Tags: ics | infix

less

Transcript and Presenter's Notes

Title: ICS 241


1
ICS 241
  • Discrete Mathematics II
  • William Albritton, Information and Computer
    Sciences Department at University of Hawaii at
    Manoa
  • For use with Kenneth H. Rosens Discrete
    Mathematics Its Applications (5th Edition)
  • Based on slides originally created by
  • Dr. Michael P. Frank, Department of Computer
    Information Science Engineering at University
    of Florida

2
Section 9.3 Tree Traversal
  • Universal address systems
  • Traversal algorithms
  • Depth-first traversal
  • Preorder traversal
  • Inorder traversal
  • Postorder traversal
  • Infix/prefix/postfix notation

3
Universal Address Systems
  • A way to label the nodes of an ordered rooted
    tree
  • Label the root with integer 0
  • Label its children from left to right with 1, 2,
    3,
  • For the next level down from vertex A, label its
    children with A.1, A.2, A.3,

4
Class Exercise
  • Exercise 3. (p. 672)
  • Each pair of students should use only one sheet
    of paper while solving the class exercises

5
Traversal Algorithms
  • Methods for visiting every node of an ordered
    rooted tree
  • Most common traversals
  • Preorder traversal
  • Inorder traversal
  • Postorder traversal

6
Preorder Traversal
  • Steps
  • Visit the root
  • Visit the leftmost node in Preorder
  • Visit the 2nd leftmost node in Preorder
  • Visit the Nth node
  • Example traversal
  • 7, 3, 1, 0, 2, 5, 12, 9, 8, 11, 15

Example
7
3
12
1
5
9
15
0
2
8
11
7
Inorder Traversal
  • Steps
  • Visit the leftmost node in Inorder
  • Visit the root
  • Visit the 2nd leftmost node in Inorder
  • Visit the Nth node
  • Example traversal
  • 0, 1, 2, 3, 5, 7, 8, 9, 11, 12, 15

Example
7
3
12
1
5
9
15
0
2
8
11
8
Postorder Traversal
  • Steps
  • Visit the leftmost node in Postorder
  • Visit the 2nd leftmost node in Postorder
  • Visit the Nth node
  • Visit the root
  • Example traversal
  • 0, 2, 1, 5, 3, 8, 11, 9, 15, 12, 7

Example
7
3
12
1
5
9
15
0
2
8
11
9
Class Exercise
  • Exercise 7. (p. 673)
  • Each pair of students should use only one sheet
    of paper while solving the class exercises

10
Infix/Prefix/Postfix Notation
  • Can use an ordered, rooted tree to represent
    arithmetic expressions
  • Leaves represent variables or numbers
  • Interior nodes represent operations
  • Operations are evaluated from the bottom of the
    tree to the top, and from the left node to the
    right node

11
Infix/Prefix/Postfix Notation
  • Infix
  • ((16)-5)((2?5)/8)
  • Prefix
  • -165/?258
  • Polish notation
  • By Jan Lukasiewicz
  • Infix
  • 165-25?8/
  • Reverse Polish notation

Example

-
/

5
?
8
1
6
2
5
12
Class Exercise
  • Exercise 23. (p. 673)
  • Each pair of students should use only one sheet
    of paper while solving the class exercises
Write a Comment
User Comments (0)
About PowerShow.com