Same Tree Recursion
Same Tree Recursion
1. **Base Case**:
- If both nodes (`p` and `q`) are `null`, return `true` (both trees are empty and identical).
- If only one of the nodes is `null`, return `false` (one tree is empty, and the other is not).
- If the values of `p` and `q` are different, return `false` (trees are not identical).
2. **Recursive Case**:
- Recursively check if the left subtrees of `p` and `q` are the same.
- Recursively check if the right subtrees of `p` and `q` are the same.
- If both the left and right subtree checks return `true`, the trees are identical.
---
---
---
This algorithm is efficient, concise, and directly solves the problem requirements.