Congrats Love bhai ... People sometimes don't understand the extent of endeavours one has put to build such a great course! Never had a doubt on completion of this course. An eligible Military officer rank person will never disappoint us with his commitment. Aye Aye Captain! Lots of Love 🤍 Abhishek (Punjab)
As stated from 13:08 that transpose needs to be done due to the reversed nature of topo sort in the stack. If I reverse the contents of the stack (using another stack), do I still need to create Transpose? I implemented this, but could not get all the test cases passed.
At 10:57, is that toposort right? 1 will call dfs for 2, so don't we get 2 at the bottom? Maybe this is the reason one cannot get SCC by (using the reverse order of toposort instead of transposing the graph )
Small doubt : we can get the topological order of any graph only if it is DIRECTED ACYCLIC Graph but here in this question the Graph has a cycle. So this is not the topological order of the graph , this is something else , what we can call it?
I know its 8 months late but I'll reply any way Think of it this way take a scc as a node then the resultant graph you get will always be a DAG so in a way we are applying topo sort to that graph but you are right technically you don't get a topological ordering of the nodes since there is a cycle but it's a topological ordering if you look at the scc as a single node
You can use topo sort for any graph but you can't write topological ordering of any cyclic graph. Don't get confused with topo sort and topological ordering
Can anyone please tell why cant we us a queue instead of stack if we use a queue to store the topological sort order , we don't need to transpose the graph but while doing it with the queue method some of the testcase get's failed .. can anyone tell why >?
I think he is just using the methodology of doing topological sort to get desired stack but if we go by definition of topological sort whatever order the stack will give upon pop will not be a topological sort but that order will serve our purpose of doing Kosarju algorithm further.
so number of connected components (as we find using revDfs) in a transposed graph is equal to the number of strongly connected components for the original graph 🤔
previous you said that the topological sort is only possible for DAG(directed acyclic graph) why you take topological sort of cyclic graph in this video
actually the intution is to sort them acc to finishing time (finding this seq. is similar to topological sort but its not topo sort as you can see in u->v , cycle prevents it from making u,v . So we wont call it as topo sort)
For all those who are wandering why is it important to transpose the graph... Consider this graph 1 0 0 2 2 1 0 3 3 4 Now if you print the topo sort you get 0 3 4 2 1 After reversing the stack if you try you get 1 2 4 3 0 if you try to do dfs from 1 you will reach 0 3 4 in one move which makes 1 0 3 4 a strongly connected component giving you count=1 instead of count=3.
Hey can any body resolve my code of this in gfg??? This gives segmatation falute also give reson void dfstopo(vector adj[], vector &visited, int V, vector &topo, int node) { visited[node]=true; for(auto k:adj[node]) { if(!visited[k]) dfstopo(adj, visited, V, topo, k); } topo.push_back(node); } void dfs(vector transpose[], vector &visited, int V, int node) { visited[node]=true; for(auto k:transpose[node]) { if(!visited[k]) dfs(transpose, visited, V, k); } }
//Function to find number of strongly connected components in the graph. int kosaraju(int V, vector& edj) { vector adj[V]; //make adjlist for(int i=0; i
the journey was very beaytiful of completing 100 videos tnku babbar sir
Congrats Love bhai ... People sometimes don't understand the extent of endeavours one has put to build such a great course! Never had a doubt on completion of this course.
An eligible Military officer rank person will never disappoint us with his commitment. Aye Aye Captain!
Lots of Love 🤍
Abhishek (Punjab)
Thanks for the heart Love bhai ! 😇
Century ho gayi bhyya congrats
Congratulations for century more to go.... 🙌❤
Bhaiya 100 videos 🔥🔥🔥🔥 congratulations for coming this far.... More more to go !!! 🖤🖤
tuzyaycha dana
As stated from 13:08 that transpose needs to be done due to the reversed nature of topo sort in the stack. If I reverse the contents of the stack (using another stack), do I still need to create Transpose? I implemented this, but could not get all the test cases passed.
bhut easy tha bhaiyaa ...subkuch samaj aya thank you...
Ye vala lecture aaj ka josh++ tha bhaiya🎉
i done 100 videos. I can't believe myself. But now i need to practice this all then i will move to DP series.
Congrats both you and i and thanks to u for all us🥳🥳🥳😍😍😍
easily explain kiya love babber ji
and this is the testimony that you delivered your promise..! congrats Love bhai
At 10:57, is that toposort right? 1 will call dfs for 2, so don't we get 2 at the bottom? Maybe this is the reason one cannot get SCC by (using the reverse order of toposort instead of transposing the graph )
Congratulations 🎊 bhaiya for 100 successful lectures you are awesome teacher and a friend ❤️
finally, I'm here.....socha nahi thaa itna tohhhhh
Congrats Love bhaiya for completing 100 great lectures !!
Thank You So Much for this wonderful video.............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
One Doubt:
Topological sort ki kyu zarurat humko Love Bhaiya?
💯 century ho gya bhaiya congratulations
This explanation of Kosaraju's algo was better than Striver's explanation.
100 videos completed congratulation and Thank you bhaiya
Congrats bhaiya.....great journey.... Even better playlist🎉🎉
#Century ho gayi
Awesome teaching By our loving Love Bhaiya.😊😊
Babbar sir your hundreds vediohas been completed so I have also watched hundreds vedio of ds course.. 👍
Thank YOu so much for your hardwork...Bhaiya
Small doubt :
we can get the topological order of any graph only if it is DIRECTED ACYCLIC Graph but here in this question the Graph has a cycle. So this is not the topological order of the graph , this is something else , what we can call it?
It's called a DFS traversal tree.
I know its 8 months late but I'll reply any way
Think of it this way take a scc as a node then the resultant graph you get will always be a DAG so in a way we are applying topo sort to that graph but you are right technically you don't get a topological ordering of the nodes since there is a cycle but it's a topological ordering if you look at the scc as a single node
Completed watching all 100 videos in 30 days 🥺
Congrats Bhaiya🎉🎉
Thank You So Much BHRATA SHREE !!!!!!!
Congratulations bhaiya for a century
Congratulations 🎉🎉 for century, abhi aur bhi fordna hain
How can you find topological order in cyclic graph, it is possible in only directed acyclic graph n?
Literally hats off for u bhaiya ❤️🔥
how can we apply topo sort in this bcz as per my knowledge topo sort is for only directed acyclic graph, but here cyclic graph is present.
Because it's directed graph
@@RaHuLKuMaR-fd1ec No Topo is only for DAG
We do not use topo sort using bfs, but we can use top sort using dfs
You can use topo sort for any graph but you can't write topological ordering of any cyclic graph. Don't get confused with topo sort and topological ordering
Congratulations for 1.5L Subscribers and 100 Videos.... Wow it has been a Amazing journey soo far. Thanx bhaiya 🔥🔥🔥🤩
The 💯 Victory 🤩🤩
Congrats sir👍🎉
Sir amazing video super duper
You kept your promise... Thank you for that. tq sir
Back to back bhaiya salute to u and me live unacademy pe bhi student huun aapka name yad rkhna bhaiya 😁😁
You kept your promise... Thank you for that... 👍
Can anyone please tell why cant we us a queue instead of stack if we use a queue to store the topological sort order , we don't need to transpose the graph but while doing it with the queue method some of the testcase get's failed .. can anyone tell why >?
Congratulations vaiya 😊😊😊
you are just amazing brother.... thanks for your efforts... 🙏🙏
how is topological sort even defined for directed cyclic graphs?
Feeling great to reach 100 videos starting in December
103 ✅completed 👍Liked 1:20
COngrats on 100 videos
great efforts sir!! 🫶
Really appreciable work!!!!
without transposing graph can we just reverse the stack
Love Babbar appreciation comment 💯👑
Finally we hit century
bhaiya i can also find transpose without using extra loop
unordered_map adj;
unordered_map trans_adj;
for(int i=0; i
Finally 🆒😀
I have a doubt .
When we created revDfs function, we used &adj , when we use &transpose, it shows an error. Why So ?
congratulations ...
if we are reversing the links so instead of using stack i tried with queue it dosen't work for every test case why?
and it works for given example.
Just Awesome!!!
U ARE KING😎😎
awesome bhaiya
Guys, test cases pass nhi ho rhein hai koi btade kahan galati kr rha hu. Code is given below.
CODE: Kosaraju's Algorithm
#include
#include
#include
void createList(vector& edges, unordered_map& adjList) {
for (int i = 0; i < adjList.size(); i++) {
int u = edges[i][0];
int v = edges[i][1];
adjList[u].push_back(v);
}
}
void topoSort(int vtx, vector& visited, stack& st, unordered_map& adjList) {
visited[vtx] = true;
for (auto neighbor: adjList[vtx]) {
if (!visited[neighbor]) {
topoSort(neighbor, visited, st, adjList);
}
}
st.push(vtx);
}
void countSCCsDFS(int vtx, vector& visited, unordered_map& transposeAdjList) {
visited[vtx] = true;
for (auto neighbor: transposeAdjList[vtx]) {
if (!visited[neighbor]) {
countSCCsDFS(neighbor, visited, transposeAdjList);
}
}
}
int stronglyConnectedComponents(int v, vector &edges) {
unordered_map adjList;
createList(edges, adjList);
// topo sort
vector visited(v, false);
stack st;
for (int i = 0; i < v; i++) {
if (!visited[i]) {
topoSort(i, visited, st, adjList);
}
}
// create a transpose graph
unordered_map transposeAdjList;
for (int i = 0; i < v; i++) {
visited[i] = false;
for (auto neighbor: adjList[i]) {
transposeAdjList[neighbor].push_back(i);
}
}
// dfs call using transposeAdjList graph
// sccs: strongly connected component(s)
int countSCCs = 0;
while (!st.empty()) {
int topVtx = st.top();
st.pop();
if (!visited[topVtx]) {
countSCCs++;
countSCCsDFS(topVtx, visited, transposeAdjList);
}
}
// no. of strongly connected component(s)
return countSCCs;
}
in createList(), for loop should iterate over edges.size() ,not adjList.size().
correction required:-
for(int i = 0;i
Topological sort can only be used in DAG, how is it working in a graph containing cycle ?
I think he is just using the methodology of doing topological sort to get desired stack but if we go by definition of topological sort whatever order the stack will give upon pop will not be a topological sort but that order will serve our purpose of doing Kosarju algorithm further.
so number of connected components (as we find using revDfs) in a transposed graph is equal to the number of strongly connected components for the original graph 🤔
just one doubt how are you applying the topological sort for a graph that is not DAG in the example also you did the recursive call for 2 wrong
Bhaiya par topological sort to acyclic graphs me hi hoti thi, isme jo aapne example liya hai usme toh cycle hai????
15 feb 2023 continuesly total 100 completed in 3 month .
or we can reverse stack also instead of graph direction
on 100th one more to go
Legacy 🔥
Good explanation
why can not we use queue and then there will be no need to reverse the order?
This Algorithm was purposed by BABA Ranchor Das Samal Das Chancher and the name was inspire by "Prerajulisation" .😂
💯💯💯
can we use queue instead of stack then there would be no need to take transpose.
Thank you 😇
previous you said that the topological sort is only possible for DAG(directed acyclic graph) why you take topological sort of cyclic graph in this video
actually the intution is to sort them acc to finishing time (finding this seq. is similar to topological sort but its not topo sort as you can see in u->v , cycle prevents it from making u,v . So we wont call it as topo sort)
@@tusharsharma6518 why cant we take queue instead of stack..then we dont need to transpose
As we pass tanspose we should write &transpose ..but bhaiya wrote adj why ?
GREAT
sir love ur vids
why we take transpose of edges
cyclic graph me topological sorting kaise lag gayi?
Toposort only valid in DAG, to bhaiya ne kyu topo sort lgya. guys koi smjha skta h
bhaiya in form.... 🙏🙏🙏
For all those who are wandering why is it important to transpose the graph...
Consider this graph
1 0
0 2
2 1
0 3
3 4
Now if you print the topo sort you get
0
3
4
2
1
After reversing the stack if you try you get 1 2 4 3 0 if you try to do dfs from 1 you will reach 0 3 4 in one move which makes 1 0 3 4 a strongly connected component giving you count=1 instead of count=3.
cycle present in eg. how we can use topological sort here
thank you soo much for this
Aap bhagwan ka kaam kar rhe hai.
keep doing it.
thank you bhaiya
Achievement ++
Century 🤗,
Consistency++;
Hey can any body resolve my code of this in gfg??? This gives segmatation falute also give reson
void dfstopo(vector adj[], vector &visited, int V, vector &topo, int node)
{
visited[node]=true;
for(auto k:adj[node])
{
if(!visited[k])
dfstopo(adj, visited, V, topo, k);
}
topo.push_back(node);
}
void dfs(vector transpose[], vector &visited, int V, int node)
{
visited[node]=true;
for(auto k:transpose[node])
{
if(!visited[k])
dfs(transpose, visited, V, k);
}
}
//Function to find number of strongly connected components in the graph.
int kosaraju(int V, vector& edj)
{
vector adj[V];
//make adjlist
for(int i=0; i
🔥🔥🔥
thanks 🔥
🔥👌
Bhaiya Graph ke thore questions to karwate
100 ❤🔥
thank u
Century 🏏
я дошёл до того что смотрю видос индуса, т.к. не могу найти ничего толкового, каждый алгоритм на каждом сайте выдаёт разный ответ
🥳✨
respect++
Sir next topic ?