Given a binary valued Undirected Graph with V vertices and E edges, the task is to find the maximum decimal equivalent among all the connected components of the graph. A binary valued graph can be considered as having only binary numbers (0 or 1) as the vertex values.
Input: E = 4, V = 7
Decimal equivalents of the connected components are as follows:
[0, 1] : Maximum possible decimal equivalent = 2 [(10)2]
[0, 0, 0] : Maximum possible decimal equivalent = 2
[1, 1] : Maximum possible decimal equivalent = 3
Hence, Maximum decimal equivalent of all components = 3
Input: E = 6, V = 10
Connected Components and decimal equivalent are as follows:
 : Maximum possible decimal equivalent = 2
[0, 0, 1, 0] : Maximum possible decimal equivalent = 8 [(1000)2]
[1, 1, 0] : Maximum possible decimal equivalent = 6
[1, 0] : Maximum possible decimal equivalent = 2
Hence, Maximum decimal equivalent of all components = 8
- The idea is to use Depth First Search Traversal to keep track of the connected components in the undirected graph as explained in this article.
- For each connected component, the binary string is stored and the equivalent decimal value is calculated.
- A global maximum is set that is compared to maximum decimal equivalent obtained after every iteration to get the final result.
Below is the implementation of the above approach:
Time Complexity: O(V2)
The DFS algorithm takes O(V + E) time to run, where V, E are the vertices and edges of the undirected graph. Further, the decimal equivalent is found at each iteration that takes an additional O(V) to compute and return the result. Hence, the overall complexity is O(V2)
- Octal equivalents of connected components in Binary valued graph
- Maximum sum of values of nodes among all connected components of an undirected graph
- Maximum number of edges among all connected components of an undirected graph
- Connected Components in an undirected graph
- Clone an undirected graph with multiple connected components
- Largest subarray sum of all connected components in undirected graph
- Sum of the minimum elements in all connected components of an undirected graph
- Count of unique lengths of connected components for an undirected graph using STL
- Program to count Number of connected components in an undirected graph
- Hexadecimal equivalents in Binary Valued Graph
- Sum of decimal equivalent of all possible pairs of Binary representation of a Number
- Convert undirected connected graph to strongly connected directed graph
- Strongly Connected Components
- Number of connected components in a 2-D matrix of strings
- Check if the length of all connected components is a Fibonacci number
- Number of connected components in a doubly linked list
- Tarjan's Algorithm to find Strongly Connected Components
- Check if a Tree can be split into K equal connected components
- Decimal Equivalent of Gray Code and its Inverse
- Maximize the decimal equivalent by flipping only a contiguous set of 0s
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.