Given a binary tree and a node K, the task is to delete the node K from it by making sure that tree shrinks from the bottom (i.e. the deleted node is replaced by bottom-most and rightmost node) using Level Order Traversal.
- Start searching from the root, the address of node which is to be deleted by traversing in level order-wise.
- Continue Traversing Tree to find the deepest and rightmost node in level order wise to find the deepest and the rightmost node.
- If the node to delete is different from rightmost deepest node, then replace the node to be deleted with righmost deepest node and delete the later node
- If the node to delete is same as rightmost deepest node, then simply delete the node.
Below is the implementation of the above approach.
Original Tree: 1 8 3 4 5 6 7 Deleting node with key 8: 1 7 3 4 5 6 Deleting node with key 1: 6 7 3 4 5 Deleting node with key 4: 6 7 3 5
- Print a Binary Tree in Vertical Order | Set 3 (Using Level Order Traversal)
- Flatten Binary Tree in order of Level Order Traversal
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Density of Binary Tree using Level Order Traversal
- General Tree (Each node can have arbitrary number of children) Level Order Traversal
- Perfect Binary Tree Specific Level Order Traversal
- Perfect Binary Tree Specific Level Order Traversal | Set 2
- Check if the level order traversal of a Binary Tree results in a palindrome
- Calculate height of Binary Tree using Inorder and Level Order Traversal
- Check if the given array can represent Level Order Traversal of Binary Search Tree
- Build Binary Tree from BST such that it's level order traversal prints sorted data
- Level Order Successor of a node in Binary Tree
- Level Order Predecessor of a node in Binary Tree
- Find the kth node in vertical order traversal of a Binary Tree
- Create a binary tree from post order traversal and leaf node array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.