Breadth-first Traversal
Understand how breadth-first traversal works to visit nodes in a binary search tree level by level using a queue. Learn to implement this traversal technique in JavaScript and grasp how to find minimum and maximum values in the tree.
We'll cover the following...
We'll cover the following...
With breadth-first traversal, we first traverse through one level of children nodes, then through one level of grandchildren nodes, then through one level of grand-grandchildren nodes, etc. In the above tree, the numbers show the sequence in which the nodes will be traversed, not the data! With breadth-first search, we can’t use a stack like we could with depth-first search: when we go from node 1 to node 2, node 2 doesn’t have any connection ...