Many problems ask how many separate groups exist, like the number of islands in a grid or friend circles in a class. Run BFS or DFS from every unvisited vertex, and each new start is a new component. It costs O(V + E) in total. If edges arrive one at a time and you need to answer "are these connected" as you go, Union-Find is a better fit.