Given a binary tree and an integer K, the task is to remove all the nodes which are multiples of K from the given binary tree.
Input: 1 / \ 2 3 / \ / 4 5 8 / \ / 6 7 9 Output: Level Order Traversal of Given Binary Tree: 1 2 3 4 5 8 6 7 9 Level Order Traversal of Updated Binary Tree: 1 5 3 7 9
- Convert the given Binary Tree to Doubly Linked List.
- Remove all nodes which are multiples of K from the created doubly linked list.
- Convert the updated doubly linked list back to a binary tree.
Below is the implementation of the above approach:
Level Order Traversal of Given Binary Tree: 1 2 3 4 5 8 6 7 9 Level Order Traversal of Updated Binary Tree: 1 5 3 7 9
- Given a binary tree, how do you remove all the half nodes?
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Minimum swap required to convert binary tree to binary search tree
- Check whether a binary tree is a full binary tree or not | Iterative Approach
- Convert a Binary Tree to Threaded binary tree | Set 2 (Efficient)
- Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue)
- Binary Tree to Binary Search Tree Conversion using STL set
- Binary Tree to Binary Search Tree Conversion
- Check if a binary tree is subtree of another binary tree | Set 2
- Check whether a binary tree is a full binary tree or not
- Check whether a given binary tree is skewed binary tree or not?
- Check if a binary tree is subtree of another binary tree | Set 1
- Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Print Binary Tree levels in sorted order | Set 3 (Tree given as 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 firstname.lastname@example.org. 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.