Basic Traversal
bfs
- Finding shortest unweighted paths
- Level-order traversal
- Finding all nodes within a certain distance
Example
dfs
- Cycle detection
- Topological sorting
- Path finding with backtracking
- Exploring deeply nested structures
Example
DFS Orderings
getPreorder
- Serializing tree structures
- Implementing prefix traversal
- Building dependency chains
Example
getPostorder
- Processing dependencies bottom-up
- Deleting tree nodes safely
- Evaluating expression trees
Example
genPreorders
- Enumerating all valid processing orders
- Testing all possible traversal paths
- Finding optimal ordering based on criteria
getPreorder() for a single canonical ordering.
Example
getPreorders
genPreorders() internally.
Note: Can be exponential. Prefer genPreorders() for lazy evaluation.
genPostorders
- Enumerating all valid bottom-up processing orders
- Testing different evaluation strategies
Example
getPostorders
genPostorders() internally.
Note: Can be exponential. Prefer genPostorders() for lazy evaluation.
Options
TraversalOptions
from- Source node ID. Default:graph.initialNodeId, else the sole node with in-degree 0