22. Symmetric Tree
The problem can be found at the following link: Question Link
My Approach
To check if a binary tree is symmetric, I recursively compare the left subtree of the root with the right subtree. The comparison is done by checking if the data of the current nodes are the same and if the left subtree of the left node is symmetric to the right subtree of the right node, and vice versa.
Time and Auxiliary Space Complexity
Time Complexity:
O(N)
, whereN
is the number of nodes in the tree.Auxiliary Space Complexity:
O(h)
, whereh
is the height of the tree (recursive stack space).
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.
Last updated