Explained with images 💻. Easy to understand. 📝
Approach\nStarting from the root, we have to check that the left and right subtrees of the tree are mirrors of each other. The tree containing a single element 
# Approach\nStarting from the root, we have to check that the left and right subtrees of the tree are mirrors of each other. The tree containing a single element root is always symmetric; we will return TRUE in this case. Otherwise, we will use the following algorithm:\n\n- We take a queue with root\'s right and left nodes.\n- Iterate a loop till the queue is not empty.\n- In each iteration, we dequeue two elements from the queue and store them in two variables, left and right.\n- If both left and right are NULL, it means that the node doesn\u2019t have any child. So, we move to the next interaction.\n- If any from left and right is NULL, it means that either the left child or right child of the node doesn\u2019t exist, which leads us to the conclusion that the tree is not symmetric; we return FALSE.\n- If the values of left and right are different, it also means that the tree is not symmetric; we return FALSE.\n- Then, we append the left node of left, the right node of right, the left node of right, and the right node of left in the queue in the same order, and we move to the next interaction.\n- After completing all interactions, if the algorithm is not returned from any step, this indicates that the tree is symmetric, so we return TRUE.\n\n![Screenshot 2024-08-18 at 11.34.29\u202FAM.png](https://assets.leetcode.com/users/images/9d515f90-bd16-4f38-a238-91262a6caf9d_1723995703.9023194.png)\n![Screenshot 2024-08-18 at 11.34.32\u202FAM.png](https://assets.leetcode.com/users/images/97bb8ded-5ea9-4120-9d25-83c601f9dd37_1723995711.2255645.png)\n![Screenshot 2024-08-18 at 11.34.35\u202FAM.png](https://assets.leetcode.com/users/images/58b910b2-f07e-455c-aafe-f734250e80b0_1723995717.696814.png)\n![Screenshot 2024-08-18 at 11.34.37\u202FAM.png](https://assets.leetcode.com/users/images/6aa17afb-5665-49ee-9726-e2a2436ca2b5_1723995729.528055.png)\n![Screenshot 2024-08-18 at 11.34.40\u202FAM.png](https://assets.leetcode.com/users/images/656ad6fd-c72c-4684-82f5-fa7a94191e1c_1723995762.855101.png)\n![Screenshot 2024-08-18 at 11.34.42\u202FAM.png](https://assets.leetcode.com/users/images/168276ed-17e3-4e2e-8a6b-1057b8420cd7_1723995772.0533068.png)\n![Screenshot 2024-08-18 at 11.34.44\u202FAM.png](https://assets.leetcode.com/users/images/8d33e3ad-4de3-493d-822c-0dc74f480f0a_1723995780.7840984.png)\n![Screenshot 2024-08-18 at 11.34.46\u202FAM.png](https://assets.leetcode.com/users/images/aaa8cc64-2707-4811-9766-01dd49048312_1723995801.8745077.png)\n![Screenshot 2024-08-18 at 11.34.48\u202FAM.png](https://assets.leetcode.com/users/images/ab2a1b43-89aa-42f3-ada0-e232090d45c2_1723995810.7984197.png)\n![Screenshot 2024-08-18 at 11.34.50\u202FAM.png](https://assets.leetcode.com/users/images/a8a4a832-9651-4bd0-9592-02a592fde8d8_1723995820.3829515.png)\n\n\n# Complexity\nTime complexity: The time complexity of this solution is  $$O(n)$$, where  n n  is the total number of nodes in the tree. This is because we traverse the entire tree once.\n\nSpace complexity: Additional space is required to store a maximum of n  elements in the queue, where n is the total number of nodes in the tree. So, the space complexity of this solution is  $$O(n)$$ .\n\n\n# Code\n```\n\nclass Solution {\n    public boolean isSymmetric(TreeNode root) {\n\n        // Create a queue to help compare nodes in pairs\n        Queue<TreeNode> queueOfNodes = new LinkedList<>();\n\n        // Add the left and right children of the root to the queue\n        queueOfNodes.add(root.left);\n        queueOfNodes.add(root.right);\n\n        // Continue processing as long as there are nodes in the queue\n        while (!queueOfNodes.isEmpty()) {\n\n            // Get the next pair of nodes from the queue\n            TreeNode left = queueOfNodes.poll();\n            TreeNode right = queueOfNodes.poll();\n\n            // If both nodes are null, continue to the next pair (they are symmetric at this level)\n            if (left == null && right == null) \n                continue;\n\n            // If one node is null and the other is not, the tree is not symmetric\n            if (left == null || right == null)\n                return false;\n\n            // If the values of the two nodes are different, the tree is not symmetric\n            if (left.val != right.val)\n                return false;\n\n            // Add the next level of nodes to the queue\n            // Check the outer pair: left\'s left with right\'s right\n            queueOfNodes.add(left.left);\n            queueOfNodes.add(right.right);\n\n            // Check the inner pair: left\'s right with right\'s left\n            queueOfNodes.add(left.right);\n            queueOfNodes.add(right.left);\n        }\n\n        // If all pairs are symmetric, return true\n        return true;\n    }\n}\n\n\n```\n\nPlease Upvote if found helpful :)\n\n
['Tree', 'Breadth-First Search', 'Binary Tree', 'C++', 'Java']