Example #1
0
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
Example #3
0
def vertex_degree(G, v):
    return len(neighbors(G, v))