Skip to main content

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:

  1. A value - the data itself (for example, a number, a string, an object).
  2. A reference to its parent (except for the root).
  3. 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 / D

Here:

  • A, B, C, D are nodes,
  • A is the root,
  • D is a leaf,
  • B is 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 ready
Premium

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