Col row row rows col col cols visited pipe returnvisited true explore neighbors
Depth First Search Assignment Answers
Question:
Coding Exercise: Connected Sinks in a Pipe System
Depth First Search Answer and Explanation
rows = len(pipe_system)
cols = len(pipe_system[0])
return
if visited[row][col] or pipe_system[row][col] == '0':
dfs(row + 1, col) # down
dfs(row, col - 1) # left
# Found an unvisited sink, start DFS
connected_sinks_count += 1
['1', '0', '0', '1', '0'],
['1', '1', '0', '1', '0'],
print("Number of connected sinks:", find_connected_sinks(pipe_system))
In this:


