Problems on Graph Data Structure and popular algorithms associated with Graphs
- Theoretical concepts
- Problems
- Patterns
- Graph is a data structure
- Graph has two components, namely:
- Node/vertex
- Edge
- There are two types of graphs:
- Undirected graphs
- Directed graphs
- Consider 2 nodes
v1
andv2
:- There are two edges
v1v2
andv2v1
in an undirected graph - There is only one edge
v1v2
in a directed graph
- There are two edges
- A cycle is a path through which we can come back to the starting position
- If there's a cycle in an Undirected graph we can call it as an Undirected cyclic graph
- When there's not a cycle we can call it as an Undirected acyclic graph
- A cycle is a path through which we can come back to the starting position
- If there's a cycle in an Undirected graph we can call it as an Undirected cyclic graph
- When there's not a cycle we can call it as an Undirected acyclic graph
- Thw edges in this graph have weights
- Thw edges in this graph have weights
- Degrees in a graph
- Degree of a vertex is the number of incoming and outgoing edges to the vertex in a graph
- The Degree(v2) = 2 in the above undirected graph
- The InDegree(v2) = 1 in the above directed graph
- The OutDegree(v2) = 1 in the above directed graph
- Property of Degree in an undirected graph
- Total degree of nodes = 2 * Edges
- The total number of degree of all the nodes is equal to twice of the number of all the edges in an undirected graph
- Path in an undirected graph
- The sequence of nodes/vertex such that none of the nodes are visited twice
- Examples:
v2 v3 v1
v2 v1
v3 v2
- Path in a directed graph
- The sequence of directed nodes/vertex such that none of the nodes are visited twice
- Examples:
v1 v2 v3
v1 v3
v2 v3