Lecture 16:
Tree Traversal
Introduction
Tree Traversals
abejknopfcdglmhi
PREORDER
jenkopbfaclgmdhi
INORDER
jhopkefbclmghida
POSTORDER
Tree Traversal Algorithms
Ordered tree traversals are based on the depth-first graph traversal. The structure of all depth-first tree traversals are the same. The diffence is in when each node is evaluated.
function traverse(node: X){ for (all child nodes Y) { traverse(Y) }}
Permutation Tree for Four Elements
Simple Maze Solving as Tree Traversal
List Representation of a Binary Tree
Edge List Representations of a Tree
Dynamic Memory Representations of a Tree
A General Tree in Dynamic Memory
Data-Tag-Next
Example: Breadth-First Traversal
Breadth-First Traversal of a Treesample Ada Code
Depth-First Traversal - Binary Dreet
Depth-First Traversal of a Tree
Implementing Depth-First Traversals
PREORDER INORDER POSTORDER
Watching the Stack
Summary
DFT Tree TraversalsPre-orderIn-orderPost-order
Permutation Trees
Simple Maze as a Tree
List Representation of a Binary Tree
Edge List Representation of a Tree
Trees in Dynamic Memory
Data-Tag-Next: a general tree node
Breadth-First TraversalsUsually on Permutation TreesIterative with a Queue
Depth-First TraveralsUsed mostly for search and sortRecursive with a Stack