Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

List all connected subgraphs with exactly k vertices

I really like the connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close than the odder of input graph, it seems like a lot of work.

def connected_subgraphs_with_k_vertices(G, k):
        for subgraph in G.connected_subgraph_iterator(k):
            if subgraph.order() ==k:
                yield subgraph

# Example usage
G = graphs.CubeGraph(8)
k=8
subgraphs = list(connected_subgraphs_with_k_vertices(G, k))
graphs_list.show_graphs(subgraphs)

List all connected subgraphs with exactly k vertices

I really like the love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close than the odder of input graph, it seems like a lot of work.

def connected_subgraphs_with_k_vertices(G, k):
        for subgraph in G.connected_subgraph_iterator(k):
            if subgraph.order() ==k:
                yield subgraph

# Example usage
G = graphs.CubeGraph(8)
k=8
subgraphs = list(connected_subgraphs_with_k_vertices(G, k))
graphs_list.show_graphs(subgraphs)

List all connected subgraphs with exactly k vertices

I love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close than to the odder of input graph, it seems like a lot of work.

def connected_subgraphs_with_k_vertices(G, k):
        for subgraph in G.connected_subgraph_iterator(k):
            if subgraph.order() ==k:
                yield subgraph

# Example usage
G = graphs.CubeGraph(8)
k=8
subgraphs = list(connected_subgraphs_with_k_vertices(G, k))
graphs_list.show_graphs(subgraphs)

List all connected subgraphs with exactly k vertices

I love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close to the odder of the input graph, it seems like a lot of work.

def connected_subgraphs_with_k_vertices(G, k):
        for subgraph in G.connected_subgraph_iterator(k):
            if subgraph.order() ==k:
                yield subgraph

# Example usage
G = graphs.CubeGraph(8)
k=8
subgraphs = list(connected_subgraphs_with_k_vertices(G, k))
graphs_list.show_graphs(subgraphs)

List all connected subgraphs with exactly k vertices

I love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close to the odder of the input graph, it seems like a lot of work.

def connected_subgraphs_with_k_vertices(G, k):
        for subgraph in G.connected_subgraph_iterator(k):
            if subgraph.order() ==k:
                yield subgraph

# Example usage
G = graphs.CubeGraph(8)
graphs.CubeGraph(6)
k=8
subgraphs = list(connected_subgraphs_with_k_vertices(G, k))
graphs_list.show_graphs(subgraphs)

List all connected subgraphs with exactly k vertices

I love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close to the odder of the input graph, graph, it seems like a lot of work.

def connected_subgraphs_with_k_vertices(G, k):
        for subgraph in G.connected_subgraph_iterator(k):
            if subgraph.order() ==k:
                yield subgraph

# Example usage
G = graphs.CubeGraph(6)
k=8
subgraphs = list(connected_subgraphs_with_k_vertices(G, k))
graphs_list.show_graphs(subgraphs)

List all connected subgraphs with exactly k vertices

I love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close to the odder of the input graph, it seems like a lot of work.

def connected_subgraphs_with_k_vertices(G, k):
        for subgraph in G.connected_subgraph_iterator(k):
            if subgraph.order() ==k:
                yield subgraph

# Example usage
G = graphs.CubeGraph(6)
k=8
k=50
subgraphs = list(connected_subgraphs_with_k_vertices(G, k))
graphs_list.show_graphs(subgraphs)

List all connected subgraphs with exactly k vertices

I love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close to the odder of the input graph, it seems like a lot of work.

def connected_subgraphs_with_k_vertices(G, k):
        for subgraph in G.connected_subgraph_iterator(k):
            if subgraph.order() ==k:
                yield subgraph

# Example usage
G = graphs.CubeGraph(6)
k=50
k=60
subgraphs = list(connected_subgraphs_with_k_vertices(G, k))
graphs_list.show_graphs(subgraphs)

List all connected subgraphs with exactly k vertices

I love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close to the odder of the input graph, it seems like a lot of work.

def connected_subgraphs_with_k_vertices(G, k):
        for subgraph in G.connected_subgraph_iterator(k):
            if subgraph.order() ==k:
                yield subgraph

# Example usage
G = graphs.CubeGraph(6)
k=60
graphs.CubeGraph(5)
k=30
subgraphs = list(connected_subgraphs_with_k_vertices(G, k))
graphs_list.show_graphs(subgraphs)

List all connected subgraphs with exactly k vertices

I love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close to the odder of the input graph, it seems like a lot of work.

def connected_subgraphs_with_k_vertices(G, k):
        for subgraph in G.connected_subgraph_iterator(k):
            if subgraph.order() ==k:
                yield subgraph

# Example usage
G = graphs.CubeGraph(5)
graphs.CubeGraph(5) #order of G is 32
k=30
subgraphs = list(connected_subgraphs_with_k_vertices(G, k))
graphs_list.show_graphs(subgraphs)

List all connected subgraphs with exactly k vertices

I love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close to the odder of the input graph, it seems like a lot of work.

def connected_subgraphs_with_k_vertices(G, k):
        for subgraph in G.connected_subgraph_iterator(k):
            if subgraph.order() ==k:
                yield subgraph

# Example usage
G = graphs.CubeGraph(5) #order of G is 32
k=30
subgraphs = list(connected_subgraphs_with_k_vertices(G, k))
graphs_list.show_graphs(subgraphs)
s=[g for g in G.connected_subgraph_iterator() if g.order()==k]

List all connected subgraphs with exactly k vertices

I love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close to the odder of the input graph, it seems like a lot It appears that there is room for improvement. Must the generation of work. kth-order subgraphs rely on (k-1)-th or even smaller-order subgraphs?

# Example usage
G = graphs.CubeGraph(5) #order of G is 32
k=30
s=[g for g in G.connected_subgraph_iterator() if g.order()==k]

List all connected subgraphs with exactly k vertices

I love connected_subgraph_iterator, but it always lists all connected subgraphs or those with at most $k$ vertices .

What if I only want to obtain connected subgraphs with exactly $k$ vertices? We can, of course, produce connected subgraphs with no more than $k$ vertices and then pick them, but when $k$ is close to the odder of the input graph, It appears that there is room for improvement. Must the generation of kth-order subgraphs rely on (k-1)-th or even smaller-order subgraphs?

# Example usage
G = graphs.CubeGraph(5) #order of G is 32
k=30
s=[g for g in G.connected_subgraph_iterator() if g.order()==k]

In Sage, must the generation of kth-order subgraphs rely on (k-1)-th or even smaller-order subgraphs?