Traversals - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Traversals

Description:

– PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 8
Provided by: comp156
Category:
Tags: traversals

less

Transcript and Presenter's Notes

Title: Traversals


1
Traversals
  • Common set of algoritms on trees are traversals
  • A way of visiting all the nodes of a tree
  • Visit is defined as performing one operation on
    a node

a
c
b
g
d
f
e
h
i
2
Traversals
  • Three basic traversals
  • Preorder
  • Postorder
  • Inorder

3
Preorder Traversal
Algorithm preOrder(v) visit(v) for each child w
of v preorder (w)
  • A traversal visits the nodes of a tree in a
    systematic manner
  • In a preorder traversal, a node is visited before
    its descendants
  • Application print a structured document

1
Make Money Fast!
2
5
9
1. Motivations
References
2. Methods
6
7
8
3
4
2.3 BankRobbery
2.1 StockFraud
2.2 PonziScheme
1.1 Greed
1.2 Avidity
Demo
4
Postorder Traversal
Algorithm postOrder(v) for each child w of
v postOrder (w) visit(v)
  • In a postorder traversal, a node is visited after
    its descendants
  • Application compute space used by files in a
    directory and its subdirectories

9
cs16/
8
3
7
todo.txt1K
homeworks/
programs/
4
5
6
1
2
DDR.java10K
Stocks.java25K
h1c.doc3K
h1nc.doc2K
Robot.java20K
Demo
5
Inorder Traversal
  • In an inorder traversal a node is visited after
    its left subtree and before its right subtree
  • More later when we discuss binary trees

6
Traversal Worksheet
Postorder
Preorder
7
Linked Structure for Trees
  • A node is represented by an object storing
  • Element
  • Parent node
  • Sequence of children nodes
  • Node objects implement the Position ADT

B
D
A
F
C
E
Write a Comment
User Comments (0)
About PowerShow.com