Editor

Find the Single Points of Failure

Advanced · Write the code · from Fault Tolerance and Redundancy: How the Internet Survives Failures

From the lesson: Where does the real Internet use redundancy?

The same idea shows up at every size: - Between continents, hundreds of cables run along the ocean floor. When a ship's anchor cuts one, traffic shifts to the others. Pages may load more slowly in the affected region, but they still load.

Read this part of the lesson

Write single_points_of_failure(network). It returns a sorted list of the devices whose failure would leave the remaining devices unable to all reach each other. When a device fails, it and all of its connections disappear.

The starter code includes the lesson's can_reach, which you may use.

chain = {'A': ['B'], 'B': ['A', 'C'], 'C': ['B']}
single_points_of_failure(chain)  ->  ['B']

If A fails, B and C can still reach each other, so A is not on the list.

def can_reach(network, start, goal):
to_visit = [start]
seen = {start}
while to_visit:
device = to_visit.pop()
if device == goal:
return True
for neighbour in network[device]:
if neighbour not in seen:
seen.add(neighbour)
to_visit.append(neighbour)
return False
def single_points_of_failure(network):
# Try removing each device, then check the devices that are left
pass

What Check runs

Your code runs first, then each of these lines, and 2 more that stay hidden. The output must match exactly.

RunsExpected output
print(single_points_of_failure({"A": ["B"], "B": ["A", "C"], "C": ["B"]}))['B']
print(single_points_of_failure({"A": ["B", "C"], "B": ["A", "C"], "C": ["A", "B"]}))[]
print(single_points_of_failure({"A": ["B", "C"], "B": ["A", "C"], "C": ["A", "B", "D"], "D": ["C", "E"], "E": ["D"]}))['C', 'D']

More Fault Tolerance exercises

All Python exercises · 50 practice problems