def distance_list(G, v): D = [[v]] observed = [v] while set(observed) != set(V(G)): temp_collection = [] for w in D[-1]: N = neighbors(G, w) for x in N: if x not in observed: observed.append(x) temp_collection.apped(x) D.append(temp_collection) return D
def greedy_coloring(G): colors = {v: None for v in V(G)} colors[V(G)[0]] = 1 for v in V(G): if colors[v] == None: N = neighbors(G,v) bad_colors = [colors[w] for w in N] j = 1 while colors[v] == None: if j not in bad_colors: colors[v] = j else: j += 1 return colors
def vertex_degree(G, v): return len(neighbors(G, v))