# 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.

```
# 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?

I'd assume that the following call should do the job but somehow it does not:

It's not obvious to modify the current code of

`connected_subgraph_iterator`

to return graphs with exactly`k`

vertices. More precisely, it's not obvious when returning non-induced subgraphs, but it's easy when we have`vertices_only == True`

or when`induced == True`

.I added this idea in the wishlist: issue 35857.

@david - do you see what's wrong with the

`graphs(...)`

call I proposed above? I do not understand why it does not work.According the documentation of

`graphs`

, when parameter`augment='vertices'`

all graphsup to`n=vertices`

are generated.