Graph Theory37 sections · 1633 units
Open in Course

Practical Tips

(Implementation advice)

Use 00-indexed arrays to avoid off-by-one errors. Make sure your timer starts at 00 and increments correctly. Test your DFS on small trees (33-55 nodes) and manually verify tintin and touttout values.

If those are wrong, everything breaks. For debugging, print the flattened array after building it. Check that subtree ranges make sense before building the segment tree. A good sanity check: tout[root] should equal n1n-1 if you use inclusive boundaries.