Hide Index
- Understanding the problem
- Understanding iterative preorder traversal
- Implement iterative preorder traversal
- Understanding iterative inorder traversal
- Implement iterative inorder traversal
- Understanding iterative postorder traversal
- Implement iterative postorder traversal
- Understanding level order traversal
- Implement level order traversal
- Challenges in construction from preorder traversal
- Challenges in construction from inorder traversal
- Challenges in construction from postorder traversal
- Understanding construction using preorder and inorder traversal
- Construct tree using preorder and inorder traversal
- Understanding construction using postorder and inorder traversal
- Construct tree using postorder and inorder traversal
Understanding iterative insertion of a leaf
As we learned in the previous lesson on recursive insertion of a leaf, the recursive traversal algorithm performs poorly for some binary tree structures because of the choice of moving only in one direction. There is another way to insert a leaf node that will perform better in those cases. We can use the iterative level order traversal to insert a leaf node.
Algorithm
The algorithm is still the same. We move in the tree using the level order traversal algorithm. This way, we only move to the next level once we have checked all the nodes for the current level.
Liking the course? Check our discounted plans to continue learning.