Skip to content

Commit

Permalink
Update Theory.
Browse files Browse the repository at this point in the history
  • Loading branch information
eminencegrs committed Nov 28, 2024
1 parent 3d9874c commit f8bf195
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Theory/BinaryTrees.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,25 @@ The result of level order traversal: `1;2;3;4;5;#;6;#;#;7;8;#;#;#;#;#;#`.
**Final result**: `1;2;3;4;5;#;6;#;#;7;8;#;#;#;#;#;#`

</details>

## Tree Depth

- The **depth** of a binary tree is the number of edges on the path from the root to a given node.
- The **max depth** of a binary tree is the length of the longest path from the root node to any leaf node.

The **max depth** of a binary tree can be computed recursively:

1. If the tree is empty (no nodes, the root node is `null`), then the max depth is `0`.
2. Otherwise: `MaxDepth = 1 + Math.Max(MaxDepth(root.Left), MaxDepth(root.Right))

#### Example:

```
1
/ \
2 3
/ \
4 5
```

The max depth of this tree is **3**.

0 comments on commit f8bf195

Please sign in to comment.