Preorder and Postorder
Explore preorder and postorder traversals in the context of depth-first search for graphs. Understand how these traversals work on rooted trees and arbitrary directed graphs, how vertex states are tracked during DFS, and how edges are classified into tree, forward, back, and cross edges. This lesson helps you implement DFS with timing to analyze graph structure and vertex relationships.
We'll cover the following...
Hopefully, we’re already familiar with preorder and postorder traversals of rooted trees, both of which can be computed using depth-first search. Similar traversal orders can be defined for arbitrary directed graphs—even if they are disconnected—by passing around a counter, as shown below. Equivalently, we can use our generic depth-first search algorithm with the following subroutines: , , and .
Algorithm
...