data_structures.binary_tree.diameter_of_binary_tree

The diameter/width of a tree is defined as the number of nodes on the longest path between two end nodes.

Attributes

root

Classes

Node

Module Contents

class data_structures.binary_tree.diameter_of_binary_tree.Node
depth() int
>>> root = Node(1)
>>> root.depth()
1
>>> root.left = Node(2)
>>> root.depth()
2
>>> root.left.depth()
1
>>> root.right = Node(3)
>>> root.depth()
2
diameter() int
>>> root = Node(1)
>>> root.diameter()
1
>>> root.left = Node(2)
>>> root.diameter()
2
>>> root.left.diameter()
1
>>> root.right = Node(3)
>>> root.diameter()
3
data: int
left: Node | None = None
right: Node | None = None
data_structures.binary_tree.diameter_of_binary_tree.root