Introduction to Graph Data Structure
Graph is a non linear data structure, it is very useful for navigational purpose in real life.
Undirected Graph - It is a set of nodes and a set of links between the nodes. Each node is called a vertex, each link is called an edge, and each edge connects two vertices.
Vertices are {1, 2, 3, 4, 5}
Edges are {(1,2), (2,3), (3,4), (4,5), (5,1), (2,1), (3,2), (4,3), (5,4), (1,5)}
Directed Graph - It is a set of vertices and a collection of directed edges that each connects an ordered pair of vertices. In this one vertix points to other and so on.
Vertices are {1, 2, 3, 4, 5}
Edges are {(2,1), (3,2), (4,3), (5,4), (1,5)}
Vertex | In-Degree | Out-Degree |
---|---|---|
1 | 1 | 1 |
2 | 1 | 1 |
3 | 1 | 1 |
4 | 1 | 1 |
5 | 1 | 1 |
Indegree of vertex is the number of edges which are coming into the vertex, While out-degree is the number of edges are going out of the vertex.