Question: in Python. The input is a DICTIONARY not a graph Problem 5 - Electricity Grid Let G be a an undirected connected graph representing the
in Python.
The input is a DICTIONARY not a graph
Problem 5 - Electricity Grid Let G be a an undirected connected graph representing the grid connecting electric plants. Write a function that checks whether this grid can function if some connection is removed. In other words, your #The in input is a dict not a Graph| if -_name == main: # keys are nodes, sets are edges graph = { 'a': {'b', 'c'}, 'b': {'a', 'd'}, 'c': {'d', 'a'}, } code should check whether the removal of any edge will leave the graph G connected. Provide an efficient algorithm. For example: graph: --- 1 1 print(always_connected(graph) == True) 1 --- alwaysConnected(graph) # returns True graph: a b 11 graph = { 'a': {'c', 'h'}, 'b': {'c', 'h', 'j'}, 'c': {'a', 'b', 'h'}, 'h': {'a', 'b', 'c'}, 'j': {'b', }, } 1 b-i1 1/ c h alwaysConnected graph) # returns False (since the removal of edge b-j will leave the graph unconnected) print(always_connected(graph) == False)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
