# Get right result with FindIndependentVertexSet\[g,{n}\] ?

**URL:** <https://community.wolfram.com/t/get-right-result-with-findindependentvertexset-g-n/14098>\
**Category:** Questions\
**Tags:** graphs-and-networks\
**Created:** [May 17, 2019, 6:47am UTC](https://community.wolfram.com/t/get-right-result-with-findindependentvertexset-g-n/14098 "2019-05-17T06:47:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lczhangmath](https://avatars.discourse-cdn.com/v4/letter/l/e9bcb4/32.png) [@lczhangmath](https://community.wolfram.com/u/lczhangmath)\
**Post date:** [May 17, 2019, 6:47am UTC](https://community.wolfram.com/t/get-right-result-with-findindependentvertexset-g-n/14098/1 "2019-05-17T06:47:13Z")

</div>

Hi?  
I konw the function **FindIndependentVertexSet[g, {n}l]** which  
finds an independent vertex set with exactly n vertices. We konw 4- Path graph, every single vertex is its 1- indepent vertex set . but we use the function FindIndependentVertexSet[g, {1}l],it returns empty set {}. **It may return {{1},{2},{3},{4}}.**  
The following text give out all of the original code proceedings. it is strange?How to solve it.

```
path4 = Graph[{{1, 2}, {2, 3}, {3, 4}}, VertexLabels -> All]
FindIndependentVertexSet[path4, {1}, All]
IndependentVertexSetQ[path,{1}]

```

 ![findindepentindex.png](https://global.discourse-cdn.com/wolfram/original/3X/9/3/93e359d1e9d34076251b0cd2b800919fbe657b13.png)

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/szhorvat/32/3531_2.png) [@szhorvat](https://community.wolfram.com/u/szhorvat)\
**Post date:** [May 24, 2019, 8:02pm UTC](https://community.wolfram.com/t/get-right-result-with-findindependentvertexset-g-n/14098/2 "2019-05-24T20:02:56Z")

</div>

This is because both `FindIndependentVertexSet` and `FindClique` finds a _maximal_ set.

While `{1}` is an independent vertex set, it is not maximal: it is a subset of `{1,3}`.

My [IGraph/M](http://szhorvat.net/mathematica/IGraphM) package provides functions to find either all independent sets / cliques, or maximal ones.

Find those of size 1:

```
In[210]:= IGIndependentVertexSets[path4, {1}]
Out[210]= {{1}, {2}, {3}, {4}}

```

Find all:

```
In[212]:= IGIndependentVertexSets[path4]
Out[212]= {{1}, {2}, {3}, {4}, {1, 3}, {1, 4}, {2, 4}}

```

However, at this point, these functions lack the ability to find only a limited number of such sets. They will always find all of them. If you need this ability, please let me know and I will consider it for future versions (no promises, but things requested by users will get higher priority).

Other relevant functions in IGraph/M are `IGMaximalIndependentVertexSets`, `IGCliques`, `IGMaximalCliques`, `IGLargestCliques`, `IGCliqueSizeCounts`, and quite a few others. In particular `IGCliques` and related functions are far faster than Mathematica’s built-ins. You will find a cool application here: [Computationally solving "Easy Cube" and "Soma Cube" games / puzzles](https://wolfram.discourse.group/t/8736/1)

Note that I have not yet transitioned all the independent vertex set functions to the new fast algorithms, so sometimes finding cliques in the complement graph may be faster than finding independent sets in the graph.

---

<div class="post-metadata">

**Author:** ![lczhangmath](https://avatars.discourse-cdn.com/v4/letter/l/e9bcb4/32.png) [@lczhangmath](https://community.wolfram.com/u/lczhangmath)\
**Post date:** [May 26, 2019, 5:30am UTC](https://community.wolfram.com/t/get-right-result-with-findindependentvertexset-g-n/14098/3 "2019-05-26T05:30:38Z")

</div>

Thank you very much for your help? Before you introduce your IGraph function, If I want to get k- IndependentVertexSets, I can only find all the vertices subset of order k and using function **IndependentVertexSetQ**. It is not convient convenient.
