Visits each DISTINCT node once (identity-deduplicated), so a shared subtree is reported once and a self-referencing DAG walks in linear time.
Visits each DISTINCT node once (identity-deduplicated), so a shared subtree is reported once and a self-referencing DAG walks in linear time.