Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 36s1 days 16 hours 1 minutes 36 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 36s1 days 16 hours 1 minutes 36 seconds.

Sign in to watch this lesson
Algorithms - Trees and Range Queries · 4:48
Hang a tree from any vertex and the lowest vertex is an end of a longest path; hang it again from there and the string between the two ends pulls tight into a diameter. We prove why the two sweeps work with a swap argument, see them break on negative weights where a tree DP joining the two deepest branches still works, and get every vertex's farthest distance from the diameter's endpoints or by rerooting.