Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

How to determine whether a graph has l cycles of length k exactly?

asked 1 year ago

licheng gravatar image

updated 1 year ago

Given integersl0, k3, and a graph, I want to know if it contains l k-cycles exactly. I could enumerate all cycles of length k using the link below and count them, but this might not be very efficient. - subgraph_search_iterator-gives-duplicate-subgraphs

G=graphs.OctahedralGraph()
H = graphs.CycleGraph(3)
print( sum(1 for _ in G.subgraph_search_iterator(H, induced=False,return_graphs=False) ) )
L = { tuple(g.edges(labels=False,sort_vertices=True,sort=True)) for g in G.subgraph_search_iterator(H, induced=False) }
print(len(L))

In an import case for me, determinie if a graph has a unique k-cycle (when k=1), I don't need to list all cycles and then check; instead, obtaining two cycles would suffice, and the algorithm stops.

Similarly, such questions can be asked about subgraphs

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 1 year ago

Max Alekseyev gravatar image

You can unroll the construction for L to an early break:

def l_kcycles(G,l,k):
    H = graphs.CycleGraph(k)
    L = set()
    for g in G.subgraph_search_iterator(H, induced=False):
        L.add( tuple(g.edges(labels=False,sort_vertices=True,sort=True)) )
        if len(L)>l:
            return False
    return len(L)==l
Preview: (hide)
link

Comments

Thanks for the solution.

mia02 gravatar imagemia02 ( 1 year ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 1 year ago

Seen: 2,918 times

Last updated: Mar 06 '24