Found 1862 Articles for Data Structure

Maximum Bipartite Matching

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

7K+ 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

930 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

1K+ 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

5K+ 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

6K+ 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

7K+ 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

Detect Cycle in a Directed Graph

karthikeya Boyini
Updated on 16-Jun-2020 11:25:14

2K+ Views

Using a Depth First Search (DFS) traversal algorithm we can detect cycles in a directed graph. If there is any self-loop in any node, it will be considered as a cycle, otherwise, when the child node has another edge to connect its parent, it will also a cycle.For the disconnected graph, there may different trees present, we can call them a forest. Now we have to detect cycle for all trees of the forest.In this approach, we will use different sets to assign nodes to perform the DFS traversal. There are three different sets, the White, Grey and the Black. ... Read More

Detect Cycle in a an Undirected Graph

Samual Sam
Updated on 16-Jun-2020 11:27:25

7K+ 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

Advertisements