# What Is Adjacent Nodes in Data Structure?

//

Heather Bennett

In data structures, adjacent nodes refer to the nodes that are directly connected to a particular node. These nodes can be found in various data structures like trees, graphs, and linked lists. Understanding adjacent nodes is essential for performing operations on these data structures efficiently.

In a tree data structure, each node can have multiple child nodes. The child nodes that are directly connected to a parent node are considered adjacent nodes.

For example, in a binary tree, each node can have at most two child nodes – left and right. These child nodes are adjacent to the parent node.

### Example:

Consider the following binary tree:

```        1
/ \
2   3
/ \
4   5
```

In this tree, the adjacent nodes of node 1 are nodes 2 and 3. Similarly, the adjacent nodes of node 2 are nodes 4 and 5.

In a graph data structure, adjacent nodes refer to the vertices that share an edge with a particular vertex. These vertices are directly connected to each other and can be reached from one another through an edge.

Consider the following graph:

```     A----B
|    |
C----D
```

In this graph, the adjacent vertices of vertex A are B and C. Similarly, the adjacent vertices of vertex B are A and D.

A linked list is a linear data structure where each element (node) contains a reference pointing to the next element. In a singly linked list, each node has only one reference to the next node. Therefore, the adjacent node of a particular node in a linked list is the next node in the sequence.

```    1 -> 2 -> 3 -> 4 -> 5