File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </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+
&nbsp; / \
12+
&nbsp; 2 3
13+
<strong>Output: </strong>3 1 2<strong>
14+
Explanation: </strong>The tree is
15+
&nbsp;&nbsp; 1&nbsp;&nbsp; (mirror) 1
16+
/&nbsp;&nbsp;\&nbsp;&nbsp; =&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /&nbsp; \
17+
2&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp; 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+
&nbsp; / \
26+
&nbsp; 20 30
27+
&nbsp; / \
28+
&nbsp; 40 60
29+
<strong>Output: </strong>30 10 60 20 40<strong>
30+
Explanation: </strong>The tree is
31+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10
32+
&nbsp;&nbsp; /&nbsp;&nbsp;&nbsp;&nbsp;\&nbsp;&nbsp;(mirror) /&nbsp;&nbsp;&nbsp; \
33+
&nbsp; 20&nbsp;&nbsp;&nbsp; 30&nbsp;&nbsp;&nbsp; =&gt; &nbsp; 30&nbsp;&nbsp;&nbsp; 20
34+
&nbsp; /&nbsp;&nbsp;\&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /&nbsp;&nbsp;&nbsp;\
35+
&nbsp;40&nbsp; 60&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 60&nbsp;&nbsp;&nbsp;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()&nbsp;</strong>that takes <strong>node </strong>as <strong>paramter&nbsp; </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:&nbsp;</strong>O(N).<br>
43+
<strong>Expected Auxiliary Space:&nbsp;</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

Comments
 (0)