Can be done using BFS. I tried this way - int NumProvinces(vector & adjMat) { q.push(0); for (int j = 0; j < numNodes; j++) { if (!visited[j]) { while (!q.empty()) { int curr = q.front(); q.pop(); for (int i = 0; i < numNodes; i++) { if (adjMat[curr][i] && !visited[i]) { q.push(i); visited[i] = true; } } } numProvince++; } } return numProvince; }
Good explanation 👏 🎉
Please use white pen instead of red since the background is black
Mam this is really a good and simple one and i was able to do following your dfs lecture logic. Thanks keerti mam.😀👍🏻
Thank god. Video came.
Awsome video mam, I finally did the bfs code for this problem
Can be done using BFS. I tried this way -
int NumProvinces(vector & adjMat)
{
q.push(0);
for (int j = 0; j < numNodes; j++)
{
if (!visited[j]) {
while (!q.empty())
{
int curr = q.front();
q.pop();
for (int i = 0; i < numNodes; i++)
{
if (adjMat[curr][i] && !visited[i])
{
q.push(i);
visited[i] = true;
}
}
}
numProvince++;
}
}
return numProvince;
}
isme naya kaya hai
thnx
😇
Can be done using BFS as well
Thanks ma'am
Teach us problems which are application of graph that can't be identified on first sight that is an application of graph
Yup! Will teach everything! Be patient! Hope you watched the last video! That was one such question!
for me light mode was better
Do you have any upcoming series on string/trie related questions ?
is time complexity of dfs is o(n2)?
yes, O(n^2)