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 | Set 2
- Check if two trees are Mirror
- 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
- 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
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Check whether a binary tree is a complete tree or not | Set 2 (Recursive Solution)
- Check if a given Binary Tree is height balanced like a Red-Black Tree
- Convert a given Binary tree to a tree that holds Logical AND property