The shared part of the route
transcript
Find the distance between two nodes of a tree. Add the two depths of the nodes. Then subtract the ancestor's depth once. It looks right. Does it hold?
Nodes two and three have depth two. Their parent, node one, has depth one. The route between them has two links.
Two plus two minus one is three. But the route has only two links. So the slip gives the wrong answer.
Each depth counts the way from the root. Both include the way to the ancestor. So that part is counted twice. Subtract it twice, not once.
Add both depths. Subtract twice the ancestor's depth. Check against a route you can count. Now it is right.
Test an ancestor that is the root. Test an ancestor deep in the tree. Test a node that is the ancestor itself.
The shared route counts twice. So take it off twice. Test an ancestor below the root. Full breakdown in the lecture.