|
| 1 | +# Mirror Tree |
| 2 | +## Easy |
| 3 | +<div class="problem-statement"> |
| 4 | +<p></p><p><span style="font-size:18px">Given a Binary Tree, convert it into its mirror.<br> |
| 5 | +<img alt="MirrorTree1" class="aligncenter size-full wp-image-663 img-responsive" src="https://contribute.geeksforgeeks.org/wp-content/uploads/mirrortrees.jpg" style="height:338px; width:591px" title="MirrorTree1"> </span></p> |
| 6 | + |
| 7 | +<p><span style="font-size:18px"><strong>Example 1:</strong></span></p> |
| 8 | + |
| 9 | +<pre><span style="font-size:18px"><strong>Input: |
| 10 | +</strong> 1 |
| 11 | + / \ |
| 12 | + 2 3 |
| 13 | +<strong>Output: </strong>3 1 2<strong> |
| 14 | +Explanation: </strong>The tree is |
| 15 | + 1 (mirror) 1 |
| 16 | +/ \ => / \ |
| 17 | +2 3 3 2 |
| 18 | +The inorder of mirror is 3 1 2</span> |
| 19 | +</pre> |
| 20 | + |
| 21 | +<p><span style="font-size:18px"><strong>Example 2:</strong></span></p> |
| 22 | + |
| 23 | +<pre><span style="font-size:18px"><strong>Input: |
| 24 | +</strong> 10 |
| 25 | + / \ |
| 26 | + 20 30 |
| 27 | + / \ |
| 28 | + 40 60 |
| 29 | +<strong>Output: </strong>30 10 60 20 40<strong> |
| 30 | +Explanation: </strong>The tree is |
| 31 | + 10 10 |
| 32 | + / \ (mirror) / \ |
| 33 | + 20 30 => 30 20 |
| 34 | + / \ / \ |
| 35 | + 40 60 60 40 |
| 36 | +The inroder traversal of mirror is |
| 37 | +30 10 60 20 40.</span></pre> |
| 38 | + |
| 39 | +<p><span style="font-size:18px"><strong>Your Task:</strong><br> |
| 40 | +Just complete the <strong>function mirror() </strong>that takes <strong>node </strong>as <strong>paramter </strong>and convert it into its mirror. The printing is done by the driver code only.</span></p> |
| 41 | + |
| 42 | +<p><span style="font-size:18px"><strong>Expected Time Complexity: </strong>O(N).<br> |
| 43 | +<strong>Expected Auxiliary Space: </strong>O(Height of the Tree).</span></p> |
| 44 | + |
| 45 | +<p><span style="font-size:18px"><strong>Constraints:</strong><br> |
| 46 | +1 ≤ Number of nodes ≤ 10<sup>5</sup><br> |
| 47 | +1 ≤ Data of a node ≤ 10<sup>5</sup></span></p> |
| 48 | +<p></p> |
| 49 | +</div> |
0 commit comments