Everything about Graph Data Structure : An Overview
Below is a Graph Data Structure
A graph consists on Vertices (also called as nodes) and Edges.
Claps and Follows are Welcome 😊 . Let’s Begin
Types of Graph
Undirected Graph
A graph which has unordered pair of vertices.
Connectivity in Undirected Graph
- Connected Graph : An undirected graph where every vertex is reachable from every other vertex.
- Bridge : It is an edge in a connected graph, which when removed will leave the graph dis-connected.
- Articulation Point : A vertex in a connected graph which when removed along with its edges then graph will become dis-connected.
- Biconnected Graph : Connected graph which does not have any articulation point is called Biconnected Graph.
Directed Graph
A graph which has ordered pair of vertices.
Connectivity in Directed Graph
- Strongly Connected Graph: A Directed Graph in which we can go from any vertex to any other vertex.
- Weekly Connected Graph: A directed graph in which if we remove the direction of edges then it will be a connected undirected graph.
Terminologies
- Simple Path: A path in which all vertices are different.
- Cycle: In a **directed graph**, a path is cycle if first and last vertex is same and number of vertices in that path is at least 2. In an un-directed graph, a path is cycle if first and last vertex is same and number of vertices is at least 3.
- Simple Cycle: A cycle where except the first and last vertex all vertices are distinct.
- Pendant Vertex : A vertex in a directed graph which has indegree = 1 and outdegree = 0
- Maximum no of edges: In an undirected graph number of edges equals n(n-1)/2. In directed graph it equals n(n-1).
- Isolated Vertex: A vertex with indegree = 0 and outdegree=0.
- Complete Graph : A graph that has maximum possible number of edges.
- Multigraph: A graph which has either loop or multiple edges is called a Multigraph.
- Simple Graph : A graph that does not have any loop or multiple edges.
- Regular Graph : A graph in which number of adjacent vertices is same for all vertex.
Transitive Closure of a Directed Graph
This is also called path matrix or reachability matrix.
It can be represented as
P(i, j) = 1 if there exist a path from i to j
P(i, j) = 0 if there exist no path from i to j
We can find transitive closure of a graph by two methods.
- Using Matrix Multiplication
- Using Warshall’s Algorithm
Do let me know if you need more info on this
Traversals
- Breadth First Search : This is way of traversal in which the all adjacent vertices are visited before going to other ones.
- Depth First Search : Here we go like parent -> child fashion till we reach end.
Shortest Path Problem
- Dijkstra Algorithm : Single Source, Non Negative Weights
- Bellman Ford Algorithm: Single Source, General Weight
- Floyd or Modified Warshall’s Algorithm: All pair shortest path, should not contain negative cycle.
Minimum Spanning Tree
- Prim’s Algorithm
- Kruskal’s Algorithm
Thanks for reading. This is not an in-depth tutorial but an overview. If you want more articles on more depth, let me know I will write that.
Until Next Time
Saquib Aftab