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 EAis the parent ofBandC.Bis the parent ofDandE.DandEare children ofB.BandCare children ofA.
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 readyPremium
A concise answer to help you respond confidently on this topic during an interview.