Graph is a non-linear data structure. It contains a set of points known as nodes (or vertices) and a set of links known as edges (or Arcs). Here edges are used to connect the vertices.
A graph G can be defined as an ordered set G(V, E) where V(G) represents the set of vertices and E(G) represents the set of edges which are used to connect these vertices.
Example
The following is a graph with 5 vertices and 6 edges.
This graph G can be defined as G = ( V , E )
Where V = {A,B,C,D,E} and E = {(A,B),(A,C)(A,D),(B,D),(C,D),(B,E),(E,D)}.
We use the following terms in graph data structure...
Individual data element of a graph is called as Vertex. Vertex is also known as node. In above example graph, A, B, C, D & E are known as vertices.
An edge is a connecting link between two vertices. Edge is also known as Arc.
An edge is represented as (startingVertex, endingVertex). For example,
in above graph the link between vertices A and B is represented as
(A,B). In above example graph, there are 7 edges (i.e., (A,B), (A,C),
(A,D), (B,D), (B,E), (C,D), (D,E)).
Edges are three types.
- Undirected Edge - An undirected egde is a bidirectional edge. If there is undirected edge between vertices A and B then edge (A , B) is equal to edge (B , A).
- Directed Edge - A directed egde is a unidirectional edge. If there is directed edge between vertices A and B then edge (A , B) is not equal to edge (B , A).
- Weighted Edge - A weighted egde is a edge with value (cost) on it.
A graph with only undirected edges is said to be undirected graph.
A graph with only directed edges is said to be directed graph.
A graph with both undirected and directed edges is said to be mixed graph.
The two vertices joined by edge are called end vertices (or endpoints) of that edge.
If a edge is directed, its first endpoint is said to be the origin of it.
If a edge is directed, its first endpoint is said to be the origin of it and the other endpoint is said to be the destination of that edge.
If there is an edge between vertices A and B then both A and B are said to be adjacent. In other words, vertices A and B are said to be adjacent if there is an edge between them.
Edge is said to be incident on a vertex if the vertex is one of the endpoints of that edge.
A directed edge is said to be outgoing edge on its origin vertex.
A directed edge is said to be incoming edge on its destination vertex.
Total number of edges connected to a vertex is said to be degree of that vertex.
Total number of incoming edges connected to a vertex is said to be indegree of that vertex.
Total number of outgoing edges connected to a vertex is said to be outdegree of that vertex.
If there are two undirected edges with same end vertices and two directed edges with same origin and destination, such edges are called parallel edges or multiple edges.
Edge (undirected or directed) is a self-loop if its two endpoints coincide with each other.
A graph is said to be simple if there are no parallel and self-loop edges.
A path is a sequence of alternate vertices and edges that starts at a vertex and ends at other vertex such that each edge is incident to its predecessor and successor vertex.
No comments:
Post a Comment