githubEdit

22. Symmetric Tree

The problem can be found at the following link: Question Linkarrow-up-right

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), where N is the number of nodes in the tree.

  • Auxiliary Space Complexity: O(h), where h 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 sectionarrow-up-right. 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-potdarrow-up-right repository.

Last updated