Found 507 Articles for Algorithms

Strongly Connected Graphs

karthikeya Boyini
Updated on 16-Jun-2020 14:16:40

4K+ Views

In a directed graph is said to be strongly connected, when there is a path between each pair of vertices in one component.To solve this algorithm, firstly, DFS algorithm is used to get the finish time of each vertex, now find the finish time of the transposed graph, then the vertices are sorted in descending order by topological sort.Input and OutputInput: Adjacency matrix of the graph. 0 0 1 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 Output: Following are strongly connected components in given ... Read More

Shortest path with exactly k Edges

Samual Sam
Updated on 16-Jun-2020 12:34:11

623 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

Maximum Bipartite Matching

karthikeya Boyini
Updated on 16-Jun-2020 12:37:58

9K+ Views

The bipartite matching is a set of edges in a graph is chosen in such a way, that no two edges in that set will share an endpoint. The maximum matching is matching the maximum number of edges.When the maximum match is found, we cannot add another edge. If one edge is added to the maximum matched graph, it is no longer a matching. For a bipartite graph, there can be more than one maximum matching is possible.Input and OutputInput: The adjacency matrix. 0 1 1 0 0 0 1 0 0 1 0 0 0 0 1 0 0 ... Read More

Shortest Path in a Directed Acyclic Graph

Ankith Reddy
Updated on 16-Jun-2020 14:20:59

1K+ Views

One weighted directed acyclic graph is given. Another source vertex is also provided. Now we have to find the shortest distance from the starting node to all other vertices, in the graph.To detect Smaller distance, we can use another algorithm like Bellman-Ford for the graph with negative weight, for positive weight the Dijkstra’s algorithm is also helpful. Here for Directed Acyclic Graph, we will use the topological sorting technique to reduce complexity.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
Updated on 16-Jun-2020 12:41:36

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

Longest Path in a Directed Acyclic Graph

Samual Sam
Updated on 16-Jun-2020 12:46:03

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

Graph Coloring

karthikeya Boyini
Updated on 16-Jun-2020 12:53:49

7K+ Views

Graph coloring problem is a special case of graph labeling. In this problem, each node is colored into some colors. But coloring has some constraints. We cannot use the same color for any adjacent vertices.For solving this problem, we need to use the greedy algorithm, but it does not guaranty to use minimum color.Input and OutputInput: Adjacency matrix of the graph. 0 0 1 0 1 0 0 1 1 1 1 1 0 1 0 0 1 1 0 1 1 1 0 1 0 Output: Node: 0, Assigned with Color: 0 Node: 1, Assigned with Color: 0 ... Read More

Fleury’s Algorithm

Chandu yadav
Updated on 16-Jun-2020 12:47:09

7K+ Views

Fleury’s Algorithm is used to display the Euler path or Euler circuit from a given graph. In this algorithm, starting from one edge, it tries to move other adjacent vertices by removing the previous vertices. Using this trick, the graph becomes simpler in each step to find the Euler path or circuit.We have to check some rules to get the path or circuit −The graph must be a Euler Graph.When there are two edges, one is bridge, another one is non-bridge, we have to choose non-bridge at first.Choosing of starting vertex is also tricky, we cannot use any vertex as ... Read More

Eulerian Path and Circuit

Samual Sam
Updated on 16-Jun-2020 13:20:51

8K+ Views

The Euler path is a path, by which we can visit every edge exactly once. We can use the same vertices for multiple times. The Euler Circuit is a special type of Euler path. When the starting vertex of the Euler path is also connected with the ending vertex of that path, then it is called the Euler Circuit.To detect the path and circuit, we have to follow these conditions −The graph must be connected.When exactly two vertices have odd degree, it is a Euler Path.Now when no vertices of an undirected graph have odd degree, then it is a ... Read More

Euler Circuit in a Directed Graph

karthikeya Boyini
Updated on 16-Jun-2020 11:20:28

2K+ Views

The Euler path is a path, by which we can visit every edge exactly once. We can use the same vertices for multiple times. The Euler Circuit is a special type of Euler path. When the starting vertex of the Euler path is also connected with the ending vertex of that path, then it is called the Euler Circuit.To check whether a graph is Eulerian or not, we have to check two conditions −The graph must be connected.The in-degree and out-degree of each vertex must be the same.Input and OutputInput: Adjacency matrix of the graph. 0 1 0 0 0 ... Read More

Advertisements