Lecture 17 Trees - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Lecture 17 Trees

Description:

Basic idea is recursion (any thing similar to induction?). A traversal algorithm ... How algebra expressions can be represented as binary trees? Infix notation ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 11
Provided by: Defa67
Category:
Tags: algebra | basic | lecture | trees

less

Transcript and Presenter's Notes

Title: Lecture 17 Trees


1
Lecture 17 Trees
  • July 21st , 2003

2
Tree--Definition
  • A tree is an acyclic, connected graph with one
    node designated as the root of the tree.
  • Special case
  • nonrooted tree (free tree)
  • Forest acyclic graph (not necessarily
    connected)
  • Parent VS children.

3
Definition (cont.)
  • Depth
  • Leaf
  • Node
  • Binary tree
  • Full binary tree
  • Complete binary tree (almost full).

4
Tree -- Applications
  • In data structure
  • Binary search tree
  • 2-3 tree
  • In file management
  • Files in computer are organized in a tree-like
    structure.
  • In biology
  • Family tree

5
Binary tree representation
  • Left child -right child representation
  • Pointer representation.
  • Example 24, practice 20

6
Tree traversal algorithms
  • Pre-order
  • In-order
  • Post-order
  • Basic idea is recursion (any thing similar to
    induction?).

7
A traversal algorithm
  • ALGORITHM PREORDER
  • Predorder (tree T)
  • write (r)
  • for i1 to t do
  • Preorder(T)
  • end for
  • end Preorder

8
Traversal--Examples
  • Example 25.
  • Practice 21
  • How algebra expressions can be represented as
    binary trees?
  • Infix notation
  • Prefix notation (Polish notation).
  • Postfix notation (reverse polish notation).
  • Practice 22.

9
Some properties of trees
  • A tree with n nodes has n-1 arcs
  • Any tree with n nodes, the total number of arc
    ends is 2n-2.
  • A binary tree has at most 2d nodes at depth d.
  • The number of leaves in any binary tree is 1 more
    than the number of nodes with two children.

10
Exercise
  • Exercises 5.2
  • 3, 10,23, 28, 38, 40, 41
Write a Comment
User Comments (0)
About PowerShow.com