Given a Tree where every node contains variable number of children, convert the tree to its mirror. Below diagram shows an example.
We strongly recommend you to minimize your browser and try this yourself first.
Node of tree is represented as a key and a variable sized array of children pointers. The idea is similar to mirror of Binary Tree. For every node, we first recur for all of its children and then reverse array of children pointers. We can also do these steps in other way, i.e., reverse array of children pointers first and then recur for children.
Below is C++ implementation of above idea.
Level order traversal Before Mirroring 10 2 34 56 100 1 7 8 9 Level order traversal After Mirroring 10 100 56 34 2 9 8 7 1
Thanks to Nitin Agrawal for providing initial implementation. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Create a mirror tree from the given binary tree
- Convert a Binary Tree into its Mirror Tree
- Check mirror in n-ary tree
- Symmetric Tree (Mirror Image of itself)
- Find mirror of a given node in Binary tree
- Number of edges in mirror image of Complete binary tree
- Sum of the mirror image nodes of a complete binary tree in an inorder way
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Check if two trees are Mirror
- Check if two trees are Mirror | Set 2
- Iterative method to check if two trees are mirror of each other
- Check if two trees are mirror of each other using level order traversal
- Maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Convert an arbitrary Binary Tree to a tree that holds Children Sum Property