You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Trees/Binary Trees/is_symmetric.c++
+51-2Lines changed: 51 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@
31
31
- Therefore, the space complexity is O(N) due to the recursion stack usage.
32
32
33
33
It's important to note that the space complexity can be optimized by using an iterative approach instead of recursion. By using an iterative algorithm that leverages a stack or queue to perform a level-order traversal, we can achieve a space complexity of O(W), where W is the maximum width (number of nodes at the same level) of the binary tree.
34
-
34
+
35
35
*/
36
36
#include<iostream>
37
37
@@ -46,7 +46,7 @@ public:
46
46
};
47
47
48
48
// SymmetricalTree checks if a binary tree is symmetrical.
49
-
boolSymmetricalTree(BinaryTree* tree) {
49
+
boolSymmetricalTreeRecursive(BinaryTree* tree) {
50
50
// Call the helper function to check if the left and right subtrees are mirrored.
0 commit comments