Pre-order traversal is the method where we start from the root of the tree, then move on to the left sub-tree if available and finally move on to the right sub-tree if available. Note if the sub-trees have other sub-trees within the tree, this method is applied again.
In-order traversal is another method of traveling through a binary tree, but is slightly different from pre-order traversal. Instead of going from root to left sub-tree to right sub-tree, in-order traversal starts from left sub-tree, then move to the root, and finally move to the right sub-tree if available. Note the method is applied recursively if more sub-trees exist within other subtrees.
Post-order traversal is the last way to travel through a binary tree and the method goes as follows: starts from left sub-tree, then move on the root of the tree, and lastly move on to the right sub-tree. Note the recursive techniques applies to this method as well.
These three traversal methods can be coded through recursion and understanding these methods is key before any coding can be done. I myself looked through the tree diagrams and traced each method on paper a couple of times before I could say i was okay with the recursive techniques.When I first stumbled into these three methods in class, I was startled because traversals was completely new to me and I was still quite new to recursion. However, I believe the problem lies in me not being prepared for the lectures due to not reading the lecture notes ahead of time. Thus, that is the main problem at hand that I must fix. Concentration is key and slacking off only leads to falling behind and is a path I would not like to walk in.
These three traversal methods can be coded through recursion and understanding these methods is key before any coding can be done. I myself looked through the tree diagrams and traced each method on paper a couple of times before I could say i was okay with the recursive techniques.When I first stumbled into these three methods in class, I was startled because traversals was completely new to me and I was still quite new to recursion. However, I believe the problem lies in me not being prepared for the lectures due to not reading the lecture notes ahead of time. Thus, that is the main problem at hand that I must fix. Concentration is key and slacking off only leads to falling behind and is a path I would not like to walk in.
No comments:
Post a Comment