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

Method depth

data_structures/binary_tree/basic_binary_tree.py:75–86  ·  view source on GitHub ↗

Returns the depth of the tree >>> BinaryTree(Node(1)).depth() 1 >>> BinaryTree.small_tree().depth() 2 >>> BinaryTree.medium_tree().depth() 4

(self)

Source from the content-addressed store, hash-verified

73 return binary_tree
74
75 def depth(self) -> int:
76 """
77 Returns the depth of the tree
78
79 >>> BinaryTree(Node(1)).depth()
80 1
81 >>> BinaryTree.small_tree().depth()
82 2
83 >>> BinaryTree.medium_tree().depth()
84 4
85 """
86 return self._depth(self.root)
87
88 def _depth(self, node: Node | None) -> int:
89 if not node:

Callers

nothing calls this directly

Calls 1

_depthMethod · 0.95

Tested by

no test coverage detected