Complete the code to initialize an adjacency list for a graph with 3 nodes.
graph = {i: [] for i in range([1])}The graph has 3 nodes, so we create keys from 0 to 2 with empty lists.
Complete the code to add an edge from node 0 to node 2 in the adjacency list.
graph[0].[1](2)
We use append to add node 2 to the adjacency list of node 0.
Fix the error in the code to create an adjacency matrix for 3 nodes.
matrix = [[0 for _ in range([1])] for _ in range(3)]
The matrix must be 3x3 for 3 nodes, so range(3) is correct.
Fill both blanks to set an edge from node 1 to node 2 in the adjacency matrix.
matrix[[1]][[2]] = 1
Set matrix[1][2] = 1 to represent an edge from node 1 to node 2.
Fill both blanks to create a dictionary comprehension that maps nodes to their degree (number of edges) in an adjacency list.
degree = {node: len([1]) for node, [2] in graph.items()}Use a dictionary comprehension with braces {}, and 'neighbors' as the variable name for the adjacency list in both places: {node: len(neighbors) for node, neighbors in graph.items()}.
