Traversals
What is a traversal? It's when you visit every node of a tree or graph using the edges.
Tree traversal
Let's talk about 3 methods of traversing trees (Note: Always start at the root)
- Depth-First-Search: Visit all the descendants of a node before visiting the sibling nodes. You have to visit some nodes more than once in a DFS, this is called backtracking
- Breadth-First-Search: Visit all children of a node before visiting sibling nodes
- Priority Search: Nodes are given priorities, and the children of the node that haven't been visited yet with the highest priority are visited first
So let's try these on a tree. Here's one I made earlier: