Graph Algorithms Articles

Page 2 of 2

Longest Path in a Directed Acyclic Graph

Samual Sam
Samual Sam
Updated on 16-Jun-2020 2K+ Views

One weighted directed acyclic graph is given. Another source vertex is also provided. Now we have to find the longest distance from the starting node to all other vertices, in the graph.We need to sort the nodes in topological sorting technique, and the result after the topological sort is stored into a stack. After that repeatedly popped from the stack and try to find the longest distance for each vertex.Input and OutputInput: The cost matrix of the graph. 0  5   3 -∞ -∞ -∞ -∞ 0   2  6 -∞ -∞ -∞ -∞  0  7  4  2 -∞ -∞ ...

Read More

How to find if a graph is Bipartite?

Arjun Thakur
Arjun Thakur
Updated on 16-Jun-2020 4K+ Views

A graph is said to be a bipartite graph, when vertices of that graph can be divided into two independent sets such that every edge in the graph is either start from the first set and ended in the second set, or starts from the second set, connected to the first set, in other words, we can say that no edge can found in the same set.Checking of a bipartite graph is possible by using the vertex coloring. When a vertex is in the same set, it has the same color, for another set, the color will change.Input and OutputInput: ...

Read More

Shortest path with exactly k Edges

Samual Sam
Samual Sam
Updated on 16-Jun-2020 707 Views

One directed graph is provided with the weight between each pair of vertices, and two vertices u and v are also provided. Our task is to find the shortest distance from vertex u to vertex v, with exactly k number of edges. To solve this problem, we will start from vertex u and go to all adjacent vertices and recur for adjacent vertices using the k value as k - 1.Input and OutputInput: The cost matrix of the graph. 0 10 3 2 ∞  0 ∞ 7 ∞  ∞ 0 6 ∞  ∞ ∞ 0 Output: Weight of the shortest ...

Read More

Check if a given graph is tree or not

karthikeya Boyini
karthikeya Boyini
Updated on 16-Jun-2020 4K+ Views

In this problem, one undirected graph is given, we have to check the graph is tree or not. We can simply find it by checking the criteria of a tree. A tree will not contain a cycle, so if there is any cycle in the graph, it is not a tree.We can check it using another approach, if the graph is connected and it has V-1 edges, it could be a tree. Here V is the number of vertices in the graph.Input and OutputInput: The adjacency matrix. 0 0 0 0 1 0 0 0 0 1 0 0 0 ...

Read More

Connectivity in a directed graph

Samual Sam
Samual Sam
Updated on 16-Jun-2020 3K+ Views

To check connectivity of a graph, we will try to traverse all nodes using any traversal algorithm. After completing the traversal, if there is any node, which is not visited, then the graph is not connected.For the directed graph, we will start traversing from all nodes to check connectivity. Sometimes one edge can have the only outward edge but no inward edge, so that node will be unvisited from any other starting node.In this case, the traversal algorithm is recursive DFS traversal.Input and OutputInput: Adjacency matrix of a graph    0 1 0 0 0    0 0 1 0 ...

Read More

Detect Cycle in a an Undirected Graph

Samual Sam
Samual Sam
Updated on 16-Jun-2020 8K+ Views

To detect if there is any cycle in the undirected graph or not, we will use the DFS traversal for the given graph. For every visited vertex v, when we have found any adjacent vertex u, such that u is already visited, and u is not the parent of vertex v. Then one cycle is detected. We will assume that there are no parallel edges for any pair of vertices.Input and Output: Adjacency matrix         0 1 0 0 0     1 0 1 1 0     0 1 0 0 1     0 1 ...

Read More

Bridges in a Graph

Samual Sam
Samual Sam
Updated on 16-Jun-2020 2K+ Views

An edge in an undirected graph is said to be a bridge, if and only if by removing it, disconnects the graph, or make different components of the graph. In a practical approach, if some bridges are present in a network when the connection of bridges is broken, it can break the whole network.Input and OutputInput: The adjacency matrix of the graph. 0 1 1 1 0 1 0 1 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 1 0 Output: Bridges in given graph: Bridge 3--4 Bridge 0--3AlgorithmbridgeFind(start, visited, disc, low, ...

Read More

Biconnected Graph

Samual Sam
Samual Sam
Updated on 16-Jun-2020 4K+ Views

An undirected graph is said to be a biconnected graph, if there are two vertex-disjoint paths between any two vertices are present. In other words, we can say that there is a cycle between any two vertices.We can say that a graph G is a bi-connected graph if it is connected, and there are no articulation points or cut vertex are present in the graph.To solve this problem, we will use the DFS traversal. Using DFS, we will try to find if there is any articulation point is present or not. We also check whether all vertices are visited by ...

Read More

Introduction to Graph Algorithms

Samual Sam
Samual Sam
Updated on 30-Jul-2019 773 Views

The graph is a non-linear data-structure, which consists finite number of nodes and a set of edges which are used to connect a pair of nodes. The graphs are used to solve some real-time problems to represent network etc. In different social networks, the graphs are used. In this Section We are going to cover − Bi-Connected Graph Checking Breadth First Search (BFS) for a Graph Bridges in a Graph Check if a given graph is tree or not Connectivity in a directed graph Depth First Search (DFS) for a Graph Detect Cycle in a an Undirected Graph Detect ...

Read More
Showing 11–19 of 19 articles
« Prev 1 2 Next »
Advertisements