+1 (845) 317-8489 [email protected]

Learning Goal: I’m working on a algorithms & data structures writing question and need the explanation and answer to help me learn.

Today we will talk about traversal in binary tree. Traversal in a Binary Tree. That how to traverse a binary tree that how to traversal a linear data structure. To traverse means that you visit a single node of the binary tree to traverse. We have 3 types of traversals on the main side Preorder Postorder or Inorder traversal. Preorder traversal means very simple meaning that what you do first You visit the Root , Then visit the Left subtree , then visit the Right subtree. Then after that you have to visit Left subtrees. And after that, that ‘s all it takes to Preorder. traversal. That is , if I do a. preorder traversal in this tree , Then what will I do first I will first visit 7 Then after. after that I will. visit the left subtree which will be the Left. subtree This one will be my Left subtreree Okay And after. I will visit the right subtree this one. The way to remember this is if you only talk about these 3 types of traversals then look at the Left , that on the left side Right is on the right side. Root comes first in preorder pre in the name of pre. Preorder traversal because I put the Root at the most pre means first. In the in order traversal the Root comes in the middle.

There is only a way to remember I am just telling from the point of view of remembering Left , Right , Root , Root in Postorder traversal. Only one point is left inorder You have put the Root in the beginning and the root in the middle. These are the 3 main types of traversals. This is a Preorder for this Left subtree Meaning of pre order is , first Root , then Left , then Right Root is 1 , Left , Right is not there , but I will finish it So , I have finished this subtree Now I want to finish this subtrees If I finish this then I will write the root first , 3 Then after that I’ll write to the Left subtrees. And after that Right subtree. We are going to see this in very detail , very soon in the upcoming videos. This way you guys can get out of this way very quickly I will also tell you the technique further for Postorder , for Inorder. With the code we will see all these things. Will focus more on concepts , will not focus on rote at all as usual