Skip to content

Commit 709a1bc

Browse files
committed
add time and space
1 parent 704e14a commit 709a1bc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Trees/Binary Trees/is_symmetric.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ bool treesAreMirrored(BinaryTree* left, BinaryTree* right) {
7474
maintain the mirror traversal. The loop continues until both stacks are empty or an asymmetry is detected.
7575
Finally, the function returns whether the tree is symmetric or not.
7676
77+
The time complexity of this algorithm is O(n), where n is the number of nodes in the binary tree, as
78+
it traverses each node once. The space complexity is O(max(d, h)), where d is the maximum width of
79+
the tree (number of nodes at the widest level) and h is the height of the tree. The space complexity
80+
depends on the maximum number of nodes stored in the stacks during the traversal.
81+
82+
7783
*/
7884
struct BinaryTree {
7985
int value;

0 commit comments

Comments
 (0)