What is an edge (edge) in a tree?
An edge is a connection between two nodes in a tree: between a parent and its child.
Formally:
An edge is a directed connection of the form
javascript
parent → childIt shows how nodes are connected to each other and defines the structure of the tree.
Example:
javascript
A
/ \
B CHere there are two edges:
A → BA → C
Properties:
- If a tree has
nnodes, it always has exactlyn - 1edges. - Edges can be used to describe paths - sequences of moves from one node to another.
Summary: An edge is the "connection" or "branch" that links nodes together and makes a tree a hierarchical structure rather than just a set of data.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.