Skip to content

Instantly share code, notes, and snippets.

View sanskarfc's full-sized avatar
👋
yo

Sanskar Sharma sanskarfc

👋
yo
View GitHub Profile
# Trivially perfect graphs are the graphs that do not have a P4 path graph or a C4 cycle graph as induced subgraphs.
# Reference: Brandstädt, Le & Spinrad (1999), theorem 6.6.1, p. 99; Golumbic (1978), theorem 2. Wolk (1962) and Wolk (1965) proved this for comparability graphs of rooted forests.
# Error: By mistake used DiGraphs here instead of undirected.
# returns true if C4 is present
def checkC4(graph):
for vertex in graph:
if(graph.degree(vertex) != 2):
return False
# Function to find all minimal separators of a graph
def find_minimal_separators(G):
separators = []
visited_separators = {}
# Initial iteration
for v in G.vertices():
N_v = set(G.neighbors(v))
S = N_v.union({v})
G_S = G.copy()