Update README.md

This commit is contained in:
bt3gl 2023-08-08 16:09:42 -07:00 committed by GitHub
parent d1123f8c75
commit 92a74485ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,32 +66,6 @@ def is_leaf(node):
<br> <br>
---
### balanced trees
<br>
* a **balanced tree** is a binary tree in which the left and right subtrees of every node differ in height by no more than 1.
<br>
```python
def height(root):
if root is None:
return -1
return 1 + max(height(root.left), height(root.right))
def is_balanced(root):
if root is None:
return True
return abs(height(root.left) - height(root.right)) < 2 and \
is_balanced(root.left) and is_balanced(root.right)
```
<br>
---- ----
@ -135,6 +109,35 @@ def height(root):
return 1 + max(height(root.left), height(root.right)) return 1 + max(height(root.left), height(root.right))
``` ```
<br>
---
### balanced trees
<br>
* a **balanced tree** is a binary tree in which the left and right subtrees of every node differ in height by no more than 1.
<br>
```python
def height(root):
if root is None:
return -1
return 1 + max(height(root.left), height(root.right))
def is_balanced(root):
if root is None:
return True
return abs(height(root.left) - height(root.right)) < 2 and \
is_balanced(root.left) and is_balanced(root.right)
```
<br>
--- ---
### tree traversal: breath-first search (level-order) ### tree traversal: breath-first search (level-order)