I dont understand any significance of ans here. I think it is unecessary here.
if it has any significance than please explain
Doubt in this Lecture
Hi Gaurav, in the final code that bhaiya has written ans is not significant because we’re directly returning false when the colors[v]==colors[u]. ans would have been significant if instead of returning false directly, we would have done something like
else if(colors[v]==colors[u]){
ans = false;
break;
}
And then at the end instead of return true, we would have written
return ans;
Basically ans is storing whether the graph is still bipartite or not, and in the current code, we’re not using its value and we’re directly returning the result. So, in this case, it can be omitted.