Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bfd63f1

Browse files
committed
max depth of bst
1 parent 365434e commit bfd63f1

File tree

1 file changed

+9
-0
lines changed
  • NonLinearDataStruc/tree

1 file changed

+9
-0
lines changed

‎NonLinearDataStruc/tree/bst.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ def findMaxNode(root): # most right
5858
return root.value, size
5959

6060

61+
def max_depth(root):
62+
if not root:
63+
return 0
64+
return 1 + max(max_depth(root.left), max_depth(root.right))
65+
66+
6167
def invertTree(root):
6268
if not root:
6369
return None
@@ -127,6 +133,9 @@ def deleteNode(root, value): # ******* important **********
127133
print('\n')
128134
print(f"Min val & size of BST: {findMinNode(rt)}, Max val & size of BST: {findMaxNode(rt)}")
129135

136+
print('\n')
137+
print(f"Max depth of bst: {max_depth(rt)}")
138+
130139
print('\nInvert Tree: left is right & right is left.')
131140
invertTree(rt)
132141
print('pre-order(root->left->right):')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /