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 number of edges among all connected components of an undirected graph
- Maximum sum of values of nodes among all connected components of an undirected graph
- Convert undirected connected graph to strongly connected directed graph
- Sum of decimal equivalent of all possible pairs of Binary representation of a Number
- Check if a path exists for a cell valued 1 to reach the bottom right corner of a Matrix before any cell valued 2
- Maximum number of edges to be removed to contain exactly K connected components in the Graph
- Sum of the minimum elements in all connected components of an undirected graph
- Largest subarray sum of all connected components in undirected graph
- Kth largest node among all directly connected nodes to the given node in an undirected graph
- Connected Components in an undirected graph
- Clone an undirected graph with multiple connected components
- Program to count Number of connected components in an undirected graph
- Count of unique lengths of connected components for an undirected graph using STL
- Maximum XOR value of maximum and second maximum element among all possible subarrays
- Hexadecimal equivalents in Binary Valued Graph
- Check if the length of all connected components is a Fibonacci number
- Decimal Equivalent of Gray Code and its Inverse
- Maximize the decimal equivalent by flipping only a contiguous set of 0s
- Program to convert Hexa-Decimal Number to its equivalent BCD
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.