0% found this document useful (0 votes)
21 views

Adjacency Matrix and List

The document discusses representations of graphs as adjacency matrices and adjacency lists. An adjacency matrix represents a graph as a binary matrix where a 1 indicates an edge between two nodes and a 0 indicates no edge. An adjacency list represents a graph as an array of lists, where each list contains the neighbors of a node.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Adjacency Matrix and List

The document discusses representations of graphs as adjacency matrices and adjacency lists. An adjacency matrix represents a graph as a binary matrix where a 1 indicates an edge between two nodes and a 0 indicates no edge. An adjacency list represents a graph as an array of lists, where each list contains the neighbors of a node.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

B

H F X

G
A
R
C E D

Y B

A
Adjacency Matrix and List
Jaenhel Mencidor
Christian De la Torre
Gian Fran Araneta
Peter Francis Espera
Ern Jan Painaga
Erik Agabon
Yosef Komanchi Javier
Graph
A
K
A Graph is a non-linear data structure consisting of nodes and edges. The
nodes are sometimes also referred to as vertices and the edges are lines or arcs
that connect any two nodes in the graph. In this presentation, we will understand
the difference between the ways of representation of the graph.
H

B
C F N
B
A
Y
A
E A
F
B
G
Q
J D
Adjacency Matrix
An adjacency matrix is a way of representing a graph as a matrix of boolean (0’s
and 1’s).
S

An Adjacency Matrix is a binary matrix in which value of [i, j] cell is 1 if there


exists an edge originating from vertex and terminating to vertex, otherwise the
B
value is 0.

Example For Undirected Graph:


J

Z N

D Initially, the entire Matrix is ​initialized to 0. If there is an edge from source to


destination, we insert 1 to both cases because we can go either way.
R

D
L
B
A

K
Example of Directed Graph

R
Direct Graph Adjacency matrix
B
E
Graph Representation of Directed graph to Adjacency Matrix

B
Initially, the entire Matrix is ​initialized to 0. If there is an edge from F
C
source to destination, we insert 1 for that destination.
G
Y
A X A
F

K
Adjacency Matrix
Adjacency List is an array of separate lists. Each element of array is a list of
corresponding neighbors (or directly connected) vertices. In other words, list of
S

Adjacency List is a list of all those vertices which is directly connected to vertex.

B Example for Undirected Graph:


J

Z N

M So, an array of list will be created of size 3, where each indices represent the
vertices. Now, vertex 0 has two neighbours (i.e, 1 and 2). So, insert vertex 1 and 2
D at indices 0 of array. Similarly, for vertex 1, it has two neighbour (i.e, 2 and 0) So,
insert vertices 2 and 0 at indices 1 of array. Similarly, for vertex 2, insert its
R

D neighbours in array of list.


L
B
Example for Directed Graph:

Graph Representation of Directed graph to Adjacency List

K
Vertex 0 has no neighbours since no edges of 0 is pointing to other vertices. For vertex H
1, it has two neighbour (i.e, 0 and 2), so, insert vertices 0 and 2 at indices 1 of array.
Similarly, for vertex 2, insert its neighbours in array of list, which is 0 in the
aforementioned example.
N
M
B
A
A Y
E
F B
F
F

R
Z

A THANK YOU FOR LISTENING!!


W
A
D
W

F
L

B
D

K
M

N
N

D
B D

B
S

A
R

H
C
J

A
A

K
Y
A

F
B
Z
R

E
N

X
A

D
D
B D L

H K

You might also like