MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / make_symmetric_tree

Function make_symmetric_tree

data_structures/binary_tree/symmetric_tree.py:38–68  ·  view source on GitHub ↗

r""" Create a symmetric tree for testing. The tree looks like this: 1 / \ 2 2 / \ / \ 3 4 4 3 Returns: Node: Root node of a symmetric tree. Example: >>> tree = make_symmetric_tree() >>> tree.data 1 >>> tree.l

()

Source from the content-addressed store, hash-verified

36
37
38def make_symmetric_tree() -> Node:
39 r"""
40 Create a symmetric tree for testing.
41
42 The tree looks like this:
43 1
44 / \
45 2 2
46 / \ / \
47 3 4 4 3
48
49 Returns:
50 Node: Root node of a symmetric tree.
51
52 Example:
53 >>> tree = make_symmetric_tree()
54 >>> tree.data
55 1
56 >>> tree.left.data == tree.right.data
57 True
58 >>> tree.left.left.data == tree.right.right.data
59 True
60 """
61 root = Node(1)
62 root.left = Node(2)
63 root.right = Node(2)
64 root.left.left = Node(3)
65 root.left.right = Node(4)
66 root.right.left = Node(4)
67 root.right.right = Node(3)
68 return root
69
70
71def make_asymmetric_tree() -> Node:

Callers

nothing calls this directly

Calls 1

NodeClass · 0.70

Tested by

no test coverage detected