⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 23s17 days 22 hours 20 minutes 23 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 23s17 days 22 hours 20 minutes 23 seconds.

Sign in to watch this lesson
Algorithms - Trees and Range Queries · 4:15
A tree is a connected graph without cycles: n - 1 edges and exactly one path between any two vertices. We pick up a 10-vertex tree by vertex 1 to root it, fill parent and depth with a dfs(v, p) that skips its parent instead of keeping a visited array, and let subtree sizes bubble up from the leaves. A path of 200,000 vertices crashes the recursive version on this Mac's 8 MB stack, so we redo it with a BFS order walked backwards, which handles a million vertices in milliseconds.