Your thought is correct. It is the problem of checking if a given graph is bipartite.
Bipartite graphs do not have cycles of odd length, so if you use a BFS to color a graph, the vertices of the same colour will be independent sets.
From Wikipedia:
If a bipartite graph is connected, its bipartition can be defined by
the parity of the distances from any arbitrarily chosen vertex v: one
subset consists of the vertices at even distance to v and the other
subset consists of the vertices at odd distance to v.
Thus, one may efficiently test whether a graph is bipartite by using
this parity technique to assign vertices to the two subsets U and V,
separately within each connected component of the graph, and then
examine each edge to verify that it has endpoints assigned to
different subsets.
The interesting fact is that independent set is Np-complete and vertex cover too, but verifing if a graph is bipartite is plynomial.
In future, for questions like this, also https://cs.stackexchange.com/ is a great place to ask.