Data Structures(Representation of a graph in data structures)

 

Representation of Graphs in Data Structures:

Graphs in data structures are used to represent the relationships between objects. Every graph consists of a set of points known as vertices or nodes connected by lines known as edges. The vertices in a network represent entities.

The most frequent graph representations are the two that follow:

  • Adjacency matrix
  • Adjacency list

You’ll look at these two representations of graphs in data structures in more detail:

Adjacency Matrix

  • A sequential representation is an adjacency matrix.
  • It's used to show which nodes are next to one another. I.e., is there any connection between nodes in a graph?
  • You create an MXM matrix G for this representation. If an edge exists between vertex a and vertex b, the corresponding element of G, gi,j = 1, otherwise gi,j = 0.
  • If there is a weighted graph, you can record the edge's weight instead of 1s and 0s.

Undirected Graph Representation

graph-representation-in-data-structure-NEW.

Directed Graph Representation

directed-graph-representation-in-data-structure.

Weighted Undirected Graph Representation 

Weight or cost is indicated at the graph's edge, a weighted graph representing these values in the matrix.

unweighted-graph-representation-in-data-structure.

Adjacency List

  • A linked representation is an adjacency list.
  • You keep a list of neighbors for each vertex in the graph in this representation. It means that each vertex in the graph has a list of its neighboring vertices.
  • You have an arra of vertices indexed by the vertex number, and the corresponding array member for each vertex x points to a singly linked list of x's neighbors.

Weighted Undirected Graph Representation Using Linked-List

linked-list-adjancency-list-graph-represenatation-in-data-structure.

Weighted Undirected Graph Representation Using an Array

arrayy-adjancency-list-graph-represenatation-in-data-structure

Comments

Popular posts from this blog

String Functions in C Language(C Language)

PHP Array Functions

Home Menu Options in Ms Word