Let G be a graph of order n. A graph G is called pancyclic if it contains a cycle of length k for every 3≤k≤n, and it is called vertex pancyclic if every vertex is contained in a cycle of length k for every 3≤k≤n.
For vertex-pancyclic graphs, we can use a subgraph search approach (as shown below). However, for vertex-pancyclicity, do we have a better method? The core step is determining whether a given vertex lies on a cycle of length.
def pancyclic(G):
for a in range(3, G.order() + 1): # Check for cycles of length 3 to n
if G.subgraph_search(graphs.CycleGraph(a)) is None:
return False # Return False immediately if a cycle of length a is missing
return True # Return True if cycles of all lengths are found