Tell us what’s happening:
I read the forum post about controlling the order of the result list and will deal with that next, but first, I can’t even get the tests to run. I added a print statement to check the creation/content of the result list and it seems right. Why won’t the tests run?
Your code so far
# am = [
# [0, 1, 0, 0],
# [1, 0, 1, 0],
# [0, 1, 0, 1],
# [0, 0, 1, 0]
# ]
def dfs_adjacency_matrix(matrix, start):
visited = [False] * len(matrix)
dfs_helper(matrix, start, visited)
node_list = []
for i in range(len(visited)):
if visited[i]:
node_list.append(i)
return node_list
def dfs_helper(matrix, node, visited):
visited[node] = True
for neighbor in range(len(matrix[node])):
if matrix[node][neighbor] == 1 and not visited[neighbor]:
dfs_helper(matrix, neighbor, visited)
print(dfs_adjacency_matrix([[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]], 1))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15 Ddg/26.1
Challenge Information:
Implement the Depth-First Search Algorithm - Implement the Depth-First Search Algorithm