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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Given a binary tree, how do you remove all the half nodes?
- Remove vowels from a string stored in a Binary Tree
- 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 if a binary tree is subtree of another binary tree using preorder traversal : Iterative
- 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)
- Difference between Binary Tree and Binary Search Tree
- Check whether a binary tree is a full binary tree or not
- 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 1
- Check if a binary tree is subtree of another binary tree | Set 2
- Check whether a given binary tree is skewed binary tree or not?
- Convert a Binary Search Tree into a Skewed tree in increasing or decreasing order
- 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)
- Check if max sum level of Binary tree divides tree into two equal sum halves
- Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
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.