Given an undirected graph, task is to find the minimum number of weakly connected nodes after converting this graph into directed one.
Weakly Connected Nodes : Nodes which are having 0 indegree(number of incoming edges).
Prerequisite : BFS traversal
Input : 4 4 0 1 1 2 2 3 3 0 Output : 0 disconnected components Input : 6 5 1 2 2 3 4 5 4 6 5 6 Output : 1 disconnected components
Approach : We find a node which helps in traversing maximum nodes in a single walk. To cover all possible paths, DFS graph traversal technique is used for this.
Do the above steps to traverse the graph. Now, iterate through graph again and check which nodes are having 0 indegree.
2 weakly connected nodes
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Maximum sum of values of nodes among all connected components of an undirected graph
- Kth largest node among all directly connected nodes to the given node in an undirected graph
- Number of connected components in a 2-D matrix of strings
- Convert undirected connected graph to strongly connected directed graph
- Number of ways to select a node from each connected component
- Check if the length of all connected components is a Fibonacci number
- Maximum number of edges among all connected components of an undirected graph
- Program to count Number of connected components in an undirected graph
- Print levels with odd number of nodes and even number of nodes
- Minimum number of Water to Land conversion to make two islands connected in a Grid
- Count the nodes whose sum with X is a Fibonacci number
- Number of special nodes in an n-ary tree
- Number of sink nodes in a graph
- Number of Unicolored Paths between two nodes
- Count the number of non-reachable nodes
- Calculate number of nodes in all subtrees | Using DFS
- Check which player visits more number of Nodes
- Level with maximum number of nodes using DFS in a N-ary tree
- Count the number of nodes at given level in a tree using BFS.
- Count the number of nodes at a given level in a tree using DFS
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.