22. Symmetric Tree
Last updated
Last updated
The problem can be found at the following link: Question Link
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 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).
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.