Hide Index
Binary Tree
0% completed
Introduction to binary trees
Array implementation of binary trees
Linked list implementation of binary trees
Recursive traversals in binary trees
Iterative traversals in binary trees
Constructing a binary tree
Insertion in binary trees
Pattern: Preorder traversal (Stateless)
Pattern: Preorder traversal (Stateful)
Pattern: Postorder traversal (Stateless)
Pattern: Postorder traversal (Stateful)
Pattern: Root to leaf path (Stateless)
Pattern: Root to leaf path (Stateful)
Pattern: Level order traversal
Pattern: Lowest common anscestor
Pattern: Simultaneous traversal
Practice: Mix traversals
Certificate
Understanding iterative insertion of a leaf
As we learned earlier, 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.