Complete the code to identify the minimum number of colors needed for register allocation.
min_colors = max_degree + [1]The minimum number of colors needed is the maximum degree of the graph plus one.
Complete the code to check if two variables interfere (cannot share the same register).
if var1 in interference_graph[[1]]:
We check if var1 is in the adjacency list of var2 to see if they interfere.
Fix the error in the code that assigns colors to variables ensuring no two adjacent nodes share the same color.
for color in range(1, [1] + 1):
The loop should run up to the minimum number of colors needed to assign registers properly.
Fill both blanks to create a dictionary comprehension that maps variables to colors only if the color is not used by adjacent variables.
color_assignment = {var: [1] for var in variables if all(color_assignment.get(adj) != [2] for adj in interference_graph[var])}The comprehension assigns a color to each variable ensuring no adjacent variable has the same color.
Fill all three blanks to complete the code that builds the interference graph from a list of variable pairs that interfere.
interference_graph = {}
for var1, var2 in variable_pairs:
interference_graph.setdefault([1], set()).add([2])
interference_graph.setdefault([3], set()).add(var1)The graph is undirected, so each variable is added to the other's adjacency set.