A girl and a robot thinking together

Think together · Start with a story

A girl draws a hierarchy: backpack, pencil case, pencil. The robot draws each object as a point and each “contains” relationship as a line.

Break down the process

Follow the numbered steps, then explain them in your own words
  1. RootStarting point
  2. BranchesConnections downward
  3. LeavesNodes with no children

A tree is a connected structure with no cycles, often used to represent hierarchy.

01Why is it called a “tree”?

A tree diagram branches out from connected points, which makes it a useful picture for relationships with levels.

02What is a tree made of?

Each point or position is a node, and connections between nodes are called edges.

03What are roots, parents, and children?

Root node

The starting node at the top of a tree drawing.

Parent node

A node directly connected to a node on the next level.

Child node

A node connected directly below another node.

Leaf node

A node with no children.

04Why does a tree not “loop back around”?

A tree is a special connected structure with no cycles.

If following edges from a node leads back to that same node in a closed loop, the structure is no longer a tree.

05How many simple paths connect two nodes in a tree?

In a connected tree, there is exactly one simple path between any two nodes.

This is a very important property of trees.

06What real-world structures look like trees?

  • Folder directories
  • Company organization charts
  • Some ways to represent a family tree
  • The hierarchy of an HTML DOM
  • Some tournament elimination structures

07Do trees have to be implemented with pointers?

No.

Trees can be represented in many ways, including node pointers, arrays, and adjacency lists.

What you have learned

  • A tree is a hierarchical, cycle-free connected structure.
  • A tree is made of nodes and edges.
  • Root, parent, child, and leaf are basic concepts.
  • There is one simple path between any two nodes in a tree.
  • Trees can be implemented in several ways in a program.

Next: What Is a Binary Tree?

Your turn to try

If two branches connect and form a cycle, is it still a tree as described here?

Ready? Open to see the explanation

No. A tree has no cycles; an undirected tree must also be connected.