Lecture 23: Tree and Graph Traversals

10/19/2020

Trees and Traversals

Tree Definition

Rooted Trees Definition

Trees

Example: File Tree System

Tree Traversal Orderings

Depth First Traversals

preOrder(BSTNode x) { if (x == null) return; print(x.key) preOrder(x.left) preOrder(x.right) }
inOrder(BSTNode x) { if (x == null) return; inOrder(x.left) print(x.key) inOrder(x.right) }
postOrder(BSTNode x) { if (x == null) return; postOrder(x.left) postOrder(x.right) print(x.key) }

A Useful Visual Trick (for Humans, not algorithms)

What Good are all These Traversals

Graphs

Trees and Hierarchical Relationships

Graph Definition

Graph Type

Graph Terminology

Graph Problems

Graph Queries

Graph Queries More Theoretically

Graph Problem Difficulty

Depth-First Traversal

s-t Connectivity

Depth First Traversal

DepthFirstPaths

Tree Vs. Graph Traversals

Tree Traversals

Graph Traversal

Summary

Summary