Back to blogone root no cycles one unique path between nodes a clear hierarchy leaves: nodes with no children, the endpoints of a tree may have cycles multiple paths no root required models general relationships If it’s hierarchical → tree. If it’s relational → graph.
November 10, 2025•5 min read•Marina
This is a Tree or a Graph?
AlgorithmsData StructuresGraphs
This is a Tree or a Graph?
Another day I was taking an AI course, and the algorithm for a search problem example didn’t look like the typical "network-style" graph. It looked much more like a tree, and that’s a great moment to ask a classic interview question:
"Is this a tree, or is this a graph?"
It matters because every tree is a graph, but not every graph is a tree.
Tree
A tree is a specialized graph, with:
Common uses: decision trees, file systems, org charts, binary search trees.
Graph
A graph is more flexible:
Common uses: social networks, transportation networks, knowledge graphs, recommendation systems.
Rule of thumb
In interviews and real-world systems, the rule of thumb is simple:
When in doubt, remember: a tree is a graph with rules.