Complete the code to start DFS from each unvisited node.
for node in graph: if node not in visited: [1](node)
We use dfs to explore nodes deeply for topological sort.
Complete the code to mark the current node as visited.
def dfs(node): visited.add([1]) for neighbor in graph[node]: if neighbor not in visited: dfs(neighbor)
We mark the current node as visited before exploring neighbors.
Fix the error in adding nodes to the result list after visiting all neighbors.
def dfs(node): visited.add(node) for neighbor in graph[node]: if neighbor not in visited: dfs(neighbor) result.[1](node)
We use append to add the node after visiting neighbors for correct order.
Fill both blanks to reverse the result list and print the topological order.
result.[1]() print(' -> '.join(str(node) for node in result[2]))
We reverse the result list in place and then print it in reversed order using slicing.
Fill all three blanks to create a dictionary comprehension filtering nodes with no outgoing edges.
no_outgoing = {node: graph[node] for node in graph if len(graph[node]) [1] [2]
print(no_outgoing[3])We check if the length of adjacency list is zero and print keys of the filtered dictionary.
