What is a node (node) in a tree?
A node is the basic element of a tree that stores data and references to other nodes.
Every node contains:
- A value - the data itself (for example, a number, a string, an object).
- A reference to its parent (except for the root).
- References to child nodes (one or several).
Types of nodes:
- Root - a node with no parent; the tree starts from it.
- Internal nodes - have at least one child.
- Leaves - have no children.
Example:
javascript
A
/ \
B C
/
DHere:
A,B,C,Dare nodes,Ais the root,Dis a leaf,Bis an internal node.
Summary: A node is the building block of a tree, storing the data and the links that define its structure.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.