img
Question:
Published on: 23 January, 2022

What is tree traversal?

Answer:

Tree traversal is a process to visit all the nodes of a tree. Because, all nodes are connected via edges (links) we always start from the root (head) node. There are three ways which we use to traverse a tree −

  • In-order Traversal
  • Pre-order Traversal
  • Post-order Traversal

See the below image of a binary search tree, and traverse it using all available methods −

  • In-order traversal − 10 14 19 27 31 35 42
  • Pre-order traversal − 27 14 10 19 35 31 42
  • Post-order traversal − 10 19 14 31 42 35 27
Random questions