Skip to content

Commit 6310890

Browse files
committed
Applying code review comments
1 parent e676647 commit 6310890

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

data_structures/binary_tree/basic_binary_tree.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ class Node:
55
"""
66

77
def __init__(self, data: int) -> None:
8-
self.data: int = data
9-
self.left: Node = None
10-
self.right: Node = None
8+
self.data = data
9+
self.left: Optional[Node] = None
10+
self.right: Optional[Node] = None
1111

1212

1313
def display(tree: Node) -> None: # In Order traversal of the tree
@@ -26,23 +26,27 @@ def display(tree: Node) -> None: # In Order traversal of the tree
2626
return
2727

2828

29-
def depth_of_tree(
30-
tree: Node,
31-
) -> int: # This is the recursive function to find the depth of binary tree.
29+
def depth_of_tree(tree: Node,) -> int:
30+
"""
31+
Recursive function that finds the depth of a binary tree.
32+
"""
33+
3234
if tree is None:
3335
return 0
3436
else:
35-
depth_l_tree: int = depth_of_tree(tree.left)
36-
depth_r_tree: int = depth_of_tree(tree.right)
37+
depth_l_tree = depth_of_tree(tree.left)
38+
depth_r_tree = depth_of_tree(tree.right)
3739
if depth_l_tree > depth_r_tree:
3840
return 1 + depth_l_tree
3941
else:
4042
return 1 + depth_r_tree
4143

4244

43-
def is_full_binary_tree(
44-
tree: Node,
45-
) -> bool: # This function returns that is it full binary tree or not?
45+
def is_full_binary_tree(tree: Node,) -> bool:
46+
"""
47+
Returns True if this is a full binary tree
48+
"""
49+
4650
if tree is None:
4751
return True
4852
if (tree.left is None) and (tree.right is None):
@@ -54,7 +58,7 @@ def is_full_binary_tree(
5458

5559

5660
def main() -> None: # Main function for testing.
57-
tree: Node = Node(1)
61+
tree = Node(1)
5862
tree.left = Node(2)
5963
tree.right = Node(3)
6064
tree.left.left = Node(4)

0 commit comments

Comments
 (0)