In this article, we will be introduced to tree traversal.

What is Tree Traversal?

Tree traversal is visiting every node once in a tree. Compared to a list, array, stack, or queue where there is only one linear path to visit all nodes, a tree does not have a specific order in which you can accomplish this. There are two approaches when it comes to tree traversal:

  • Depth-First Search — Exploring as far as possible down a branch before backtracking. Within depth-first search, there are three main orders; preOrder, postOrder, and inOrder.
  • Breadth-First Search — Explore all neighbor nodes at the current depth, before moving on to the next depth level.

#javascript #web-development #data-structures #algorithms #developer

Tree Traversal with JavaScript
1.60 GEEK