Grokking Tree Coding Patterns for Interviews
0% completed
Introduction to Tree Depth First Search Pattern
The Tree Depth-First Search (DFS) traversal is a key technique in binary tree operations. It focuses on exploring one branch of the tree as far as possible before backtracking. This approach is useful for problems requiring tree traversal or handling hierarchical data.
The main types of DFS traversals include:
- Pre-order Traversal: Visit the root node first, then the left subtree, and finally the right subtree.
- In-order Traversal: Visit the left subtree first, then the root node, and finally the right subtree.
.....
.....
.....
Like the course? Get enrolled and start learning!
Faraz Ahmed
· 4 months ago
why return Max Integer for base case, if there is no right or left for a current node, cant we return 0?
lets take this example: 3 / 1
here for 3 the left is 1 and right is 0 , the minimum for left subtree and right subtree of 3 will not be 3 itself??
leftSum = 1 right Sum = 0
sum for this node: 3 + Min(1,0) = 3
Show 1 reply