Trees are recursive. Arrays are linear. Many tree problems become easier when you flatten the tree into an array. In this section, I'll show you the Euler tour technique. You will walk the tree once and convert it to an array where every subtree maps to a contiguous range.
This lets you use segment trees and other array tools on tree problems. By the end, you will solve subtree and path queries in time instead of .