Mirror Tree
Given a Binary Tree, convert it into its mirror
Algorithm:
- Traverse tree in PreOrder
- If
node is null
thenreturn null
- Create mirror_node with original_node.data
mirror_node.left = recursively call with original_node.right
mirror_node.right = recursively call with original_node.left
return mirror_node
- If
Latest Source Code:
Github: BinaryMirrorTreeCreator.java
Output:
1 / \ / \ 3 2 / \ 5 4 Mirror Tree: 1 / \ / \ 2 3 / \ 4 5