Check if a binary tree is symmetric (i.e., a mirror of itself). Parameters: tree: The root node of the binary tree. Returns: bool: True if the tree is symmetric, False otherwise. Example: >>> is_symmetric_tree(make_symmetric_tree()) True >>> is_symmetric_tree(
(tree: Node)
| 102 | |
| 103 | |
| 104 | def is_symmetric_tree(tree: Node) -> bool: |
| 105 | """ |
| 106 | Check if a binary tree is symmetric (i.e., a mirror of itself). |
| 107 | |
| 108 | Parameters: |
| 109 | tree: The root node of the binary tree. |
| 110 | |
| 111 | Returns: |
| 112 | bool: True if the tree is symmetric, False otherwise. |
| 113 | |
| 114 | Example: |
| 115 | >>> is_symmetric_tree(make_symmetric_tree()) |
| 116 | True |
| 117 | >>> is_symmetric_tree(make_asymmetric_tree()) |
| 118 | False |
| 119 | """ |
| 120 | if tree: |
| 121 | return is_mirror(tree.left, tree.right) |
| 122 | return True # An empty tree is considered symmetric. |
| 123 | |
| 124 | |
| 125 | def is_mirror(left: Node | None, right: Node | None) -> bool: |
nothing calls this directly
no test coverage detected