Skip to content

Euler Tour / Subtree Queries Ladder

This ladder is for the first tree-query lane where a subtree becomes one array interval and no heavy path machinery is needed.

Who This Is For

Use this lane if:

  • rooted-tree ideas already make sense
  • subtree language feels stable
  • path-query machinery like HLD still feels too heavy for the statement in front of you

Warm-Up

  • subtree sizes
  • entry times tin / tout
  • one DFS order that writes each node once

Good compare points:

Target skill:

  • say why a subtree becomes one contiguous interval in single-entry DFS order

Core

  • flatten the rooted tree into one entry-order array
  • map node u to one position tin[u]
  • answer subtree sum/count on [tin[u], tout[u])
  • exact flagship rep: Subtree Queries

Target skill:

  • know when one subtree query is already just one range query

Stretch

Target skill:

  • distinguish subtree-only flattening from path-query decompositions

Retrieval Layer

Exit Criteria

You are ready to move on when:

  • you can explain why [tin[u], tout[u]) is exactly the subtree of u
  • you know when Fenwick is enough after flattening and when you need a segment tree instead
  • you can say clearly why HLD is unnecessary for subtree-only queries

External Practice