Tree Traversal


** NOTE: Sample source codes will be uploaded soon.**

Why do we use tree traversal algorithm?

A tree traversal refers to a specific order in which to trace the nodes of a tree. There are 3 common tree traversals

  1. in-order traversal
    • left, root, right
    • This traversal shows sorted sequence of nodes.
  2. pre-order traversal
    • root, left, right
    • When you want to duplicate a tree, you can use this traversal.
  3. post-order traversal
    • left, right, root
    • This is the depth-first approach. So we can use this traversal when we free the memories assigned to nodes.

Related link