Preorder and Postorder
Explore how to implement preorder and postorder traversals on directed graphs using depth-first search in Java. Learn the timing of vertex visits, classify edges, and understand recursion stacks to deepen your graph algorithm knowledge.
We'll cover the following...
We'll cover the following...
Hopefully, you are already familiar with the 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
...