Graph
Graph
Graph
Cycle: A cycle is a path that starts and ends at the same vertex, with no
repeated vertices or edges in between.
Relation of graph
Sequential representation,
A "sequential representation" is not a standard term in graph theory.
However, if you meant to refer to representing a graph using a sequential
or linear data structure, one common approach is an "adjacency list."
Adjacency List:
In an adjacency list representation, you store the graph as a collection of
lists or arrays. Each vertex is associated with a list that contains its
neighboring vertices. This is a space-efficient way to represent graphs,
especially when the graph is sparse (has relatively few edges).
example:
Suppose you have a graph with three vertices and the following edges:
Vertex A is connected to B and C.
Vertex B is connected to A.
Vertex C is connected to A.
You could represent this graph using an adjacency list as follows:
A: [B, C]
B: [A]
C: [A]
Each vertex (A, B, C) is associated with a list of its neighboring vertices.
This representation makes it easy to find the neighbors of any given
vertex and is efficient in terms of memory usage for sparse graphs.
Adjacency List:
Each vertex in the graph is represented as a node in a linked list.
For each vertex, you create a linked list (or an array of linked lists) to
store its neighboring vertices.
Each node in the linked list contains the identifier of the neighboring
vertex and, optionally, any edge weights or other relevant information.
Example:
Let's consider a simple undirected graph with three vertices A, B, and C
and the following edges:
A is connected to B and C.
B is connected to A.
C is connected to A.
The linked representation of this graph would look like this:
A -> B -> C
B -> A
C -> A
Here, each vertex has a linked list of its adjacent vertices. For instance,
the linked list associated with vertex A contains B and C, indicating that
A is connected to both B and C.
Undirected Graph:
In an adjacency matrix for an undirected graph, the matrix is symmetric
because the connection between two vertices A and B is the same as the
connection between B and A. If there's an edge between A and B, it's
also represented in the matrix for B and A.
A B C
A 0 1 0
B 1 0 1
C 0 1 0
Directed Graph :
Example for a directed graph with vertices A, B, and C and edges A ->
B, B -> C:
A B C
A 0 1 0
B 0 0 1
C 0 0 0
In this example, there is an edge from A to B (A -> B) and from B to C
(B -> C).
The diagonal entries (e.g., A-A, B-B, C-C) are typically 0 in simple
graphs because a vertex is not connected to itself.
The values in the matrix can be 1 (indicating an edge) or 0 (indicating no
edge).
For weighted graphs, the matrix can contain weights instead of 0s and
1s.
Adjacency matrices are useful for various graph algorithms and
operations, and their structure depends on whether the graph is directed
or undirected.