Skip to main content

What are a parent and a child (parent / child)?

In a tree, the terms parent and child describe the hierarchical relationships between nodes.

Parent:

  • a node from which an edge goes out to another node;
  • every node (except the root) has exactly one parent.

Child:

  • a node that is connected to a parent through an edge and sits one level lower;
  • a node can have several children (0, 1, 2, ...).

Example:

javascript
A / \ B C / \ D E
  • A is the parent of B and C.
  • B is the parent of D and E.
  • D and E are children of B.
  • B and C are children of A.

Summary: A parent is a node higher up in the hierarchy, a child is a node lower down, connected to it through an edge.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.