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
- 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
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Check if two trees are Mirror
- Mirror characters of a string
- Mirror of matrix across diagonal
- Mirror of a point through a 3 D plane
- Check if two trees are Mirror | Set 2
- Iterative method to check if two trees are mirror of each other
- Program for triangular pattern (mirror image around 0)
- Find mirror image of a point in 2-D plane
- C Program for focal length of a spherical mirror
- Program to print mirror image of Swastika Pattern