Mental Model
The diameter of a tree is the longest path between any two nodes. We find it by checking the longest paths through each node using dynamic programming.
Analogy: Imagine a network of roads connecting towns. The diameter is the longest route you can drive without repeating roads. We find it by looking at the longest two roads leaving each town and combining them.
1
/ \
2 3
/ \
4 5
Each number is a node. Arrows show connections. The diameter is the longest path between any two nodes.