Overview
Last updated
Last updated
Traversal algorithms are used to iterate through data structures that can be iterated in different ways (mostly trees and graphs).
When iterating a data structure like a tree, we can prioritize iterations in two main ways, either breadth or depth.
If we prioritize depth, we will "descend" through each branch of the tree, going from the head to the leaf of each branch.
If we prioritize breadth, we will go through each tree "level" horizontally, iterating through all nodes that are on the same level before "descending" to the next level.
Which one we choose will depend largely on what value we're looking for in our iteration and how our data structure is built.