The algorithm has three main checks:
If both nodes are null, return true (empty trees match).
If one node is null and the other is not, return false (structure mismatch).
If both nodes exist, check if their values are equal.
If not, return false. If yes, recursively check left subtrees and right subtrees. You combine the recursive results with AND. Both left and right must match for the whole tree to match. This is a clean application of divide and conquer on tree structure.
This runs in time and uses space.