Skip to content

Commit 59ba7d7

Browse files
committed
2 parents 1bf66a0 + 871788c commit 59ba7d7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

data_structures/binary_tree/binary_tree_mirror.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ def mirror_subtree(tree: dict, root: int):
88
if right:
99
mirror_subtree(tree, right)
1010

11+
1112
def mirror_binary_tree(tree: dict, root: int = 1) -> dict:
1213
"""
1314
Returns the mirror of the given binary tree starting from the root.
14-
15+
1516
>>> mirror_binary_tree({1: [2, 3], 2: [4, 5], 3: [6, 7], 7: [8, 9]}, 1)
1617
{1: [3, 2], 2: [5, 4], 3: [7, 6], 7: [9, 8]}
1718
>>> mirror_binary_tree({1: [2, 3], 2: [4, 5], 3: [6, 7], 4: [10, 11]}, 1)
@@ -35,8 +36,10 @@ def mirror_binary_tree(tree: dict, root: int = 1) -> dict:
3536
mirror_subtree(mirrored_tree, root)
3637
return mirrored_tree
3738

39+
3840
if __name__ == "__main__":
3941
import doctest
42+
4043
doctest.testmod()
4144

4245
binary_tree = {1: [2, 3], 2: [4, 5], 3: [6, 7], 7: [8, 9]}

0 commit comments

Comments
 (0)