# What Is Incidence Matrix in Data Structure?

//

Larry Thompson

In data structure, the incidence matrix is a representation of a graph. It is a two-dimensional matrix that describes the relationship between vertices and edges in a graph. Each row of the matrix represents a vertex, and each column represents an edge.

## Definition

The incidence matrix is defined as follows:

Syntax:

`<ul>`
`<li>` Let V be the set of vertices in the graph
`<li>` Let E be the set of edges in the graph
`<li>` Let n be the number of vertices in the graph
`<li>` Let m be the number of edges in the graph

Pseudocode:

`<ul>`
`<li>` Create an empty 2D array with dimensions [n][m]
`<li>` For each vertex v∈V and edge e∈E, assign 1 to matrix[v][e] if v is incident to e, otherwise assign 0

## Example

To better understand how an incidence matrix works, let’s consider a simple example:

G = (V, E)

• V = {A, B, C}
• E = {e1, e2}

We can represent this graph using an incidence matrix as follows:

Incidence Matrix:

•    e1 e2
• A    1   0
• B    1   1
• C    0   1

## Properties and Applications

The incidence matrix has several properties and applications:

### 1. Compact representation:

The incidence matrix provides a compact representation of a graph compared to other representations like adjacency lists or adjacency matrices. It only requires O(n * m) space, where n is the number of vertices and m is the number of edges.

### 2. Edge-vertex relationship:

The incidence matrix clearly shows the relationship between edges and vertices in a graph.

Each row represents a vertex, and each column represents an edge. The value at matrix[v][e] indicates whether vertex v is incident to edge e.

### 3. Graph operations:

The incidence matrix enables efficient implementation of various graph operations such as adding or removing vertices or edges, checking if two vertices are adjacent, finding all neighbors of a vertex, etc.

## Conclusion

In summary, the incidence matrix is a useful data structure for representing graphs. It provides a compact representation of the edge-vertex relationship in a graph and enables efficient implementation of various graph operations.