Lecture 100: Kosaraju's Algorithm for Strongly Connected Components || C++ Placement Series

Поделиться
HTML-код
  • Опубликовано: 13 янв 2025

Комментарии • 130

  • @studygainer5482
    @studygainer5482 Год назад +5

    the journey was very beaytiful of completing 100 videos tnku babbar sir

  • @AnonymousCoder7
    @AnonymousCoder7 2 года назад +61

    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)

  • @chiragchandelteaches200
    @chiragchandelteaches200 2 года назад +4

    Century ho gayi bhyya congrats

  • @shubhamkhare26
    @shubhamkhare26 2 года назад +11

    Congratulations for century more to go.... 🙌❤

  • @anushkayachit
    @anushkayachit 2 года назад +15

    Bhaiya 100 videos 🔥🔥🔥🔥 congratulations for coming this far.... More more to go !!! 🖤🖤

  • @Aryan-se7zh
    @Aryan-se7zh Год назад +6

    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.

  • @prashantbirajdar9271
    @prashantbirajdar9271 2 года назад +2

    bhut easy tha bhaiyaa ...subkuch samaj aya thank you...

  • @vmstudy9965
    @vmstudy9965 7 месяцев назад +1

    Ye vala lecture aaj ka josh++ tha bhaiya🎉

  • @Profnegi
    @Profnegi Год назад +5

    i done 100 videos. I can't believe myself. But now i need to practice this all then i will move to DP series.

  • @vishalgarna4580
    @vishalgarna4580 Год назад +3

    Congrats both you and i and thanks to u for all us🥳🥳🥳😍😍😍

  • @chandrabhanvishwakarma4824
    @chandrabhanvishwakarma4824 Месяц назад

    easily explain kiya love babber ji

  • @piyushjoshi1939
    @piyushjoshi1939 2 года назад

    and this is the testimony that you delivered your promise..! congrats Love bhai

  • @ShubhamKumar-ot4bc
    @ShubhamKumar-ot4bc Год назад +3

    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 )

  • @study_with_kris5287
    @study_with_kris5287 2 года назад +2

    Congratulations 🎊 bhaiya for 100 successful lectures you are awesome teacher and a friend ❤️

  • @vimalrai2092
    @vimalrai2092 Год назад

    finally, I'm here.....socha nahi thaa itna tohhhhh

  • @HeyMr.OO7
    @HeyMr.OO7 2 года назад

    Congrats Love bhaiya for completing 100 great lectures !!

  • @stith_pragya
    @stith_pragya Год назад +1

    Thank You So Much for this wonderful video.............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
    One Doubt:
    Topological sort ki kyu zarurat humko Love Bhaiya?

  • @focus.placement5589
    @focus.placement5589 2 года назад

    💯 century ho gya bhaiya congratulations

  • @shibainu7500
    @shibainu7500 9 месяцев назад +1

    This explanation of Kosaraju's algo was better than Striver's explanation.

  • @harikrushnasuhagiya3925
    @harikrushnasuhagiya3925 2 года назад

    100 videos completed congratulation and Thank you bhaiya

  • @KACodes
    @KACodes 2 года назад

    Congrats bhaiya.....great journey.... Even better playlist🎉🎉
    #Century ho gayi

  • @ayushraj6525
    @ayushraj6525 2 года назад

    Awesome teaching By our loving Love Bhaiya.😊😊

  • @sukhjitsingh959
    @sukhjitsingh959 2 года назад

    Babbar sir your hundreds vediohas been completed so I have also watched hundreds vedio of ds course.. 👍

  • @Neoshiva
    @Neoshiva Год назад +1

    Thank YOu so much for your hardwork...Bhaiya

  • @ankitmusic13
    @ankitmusic13 2 года назад +4

    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?

    • @trndsttr7585
      @trndsttr7585 Год назад

      It's called a DFS traversal tree.

    • @ihave997
      @ihave997 Год назад +1

      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

  • @jayantasudhani2761
    @jayantasudhani2761 Год назад +2

    Completed watching all 100 videos in 30 days 🥺

  • @Arajka_Raj
    @Arajka_Raj 9 месяцев назад

    Congrats Bhaiya🎉🎉

  • @rachit_joshi
    @rachit_joshi 6 месяцев назад

    Thank You So Much BHRATA SHREE !!!!!!!

  • @ankitrajpootr
    @ankitrajpootr 2 года назад

    Congratulations bhaiya for a century

  • @codingaid2753
    @codingaid2753 2 года назад

    Congratulations 🎉🎉 for century, abhi aur bhi fordna hain

  • @adityaagarwal3511
    @adityaagarwal3511 2 года назад +3

    How can you find topological order in cyclic graph, it is possible in only directed acyclic graph n?

  • @dEviL_bIsWaJiT
    @dEviL_bIsWaJiT 2 года назад

    Literally hats off for u bhaiya ❤️🔥

  • @AryanKumar-cc7ku
    @AryanKumar-cc7ku 2 года назад +19

    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.

    • @RaHuLKuMaR-fd1ec
      @RaHuLKuMaR-fd1ec 2 года назад

      Because it's directed graph

    • @breakthebones
      @breakthebones 2 года назад +1

      @@RaHuLKuMaR-fd1ec No Topo is only for DAG

    • @adityauniyal8632
      @adityauniyal8632 2 года назад +3

      We do not use topo sort using bfs, but we can use top sort using dfs

    • @drillinthereel2752
      @drillinthereel2752 2 года назад +11

      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

  • @VishalGupta-xw2rp
    @VishalGupta-xw2rp 2 года назад

    Congratulations for 1.5L Subscribers and 100 Videos.... Wow it has been a Amazing journey soo far. Thanx bhaiya 🔥🔥🔥🤩

  • @aashishrangdal9614
    @aashishrangdal9614 2 года назад +1

    The 💯 Victory 🤩🤩

  • @stepone_9555
    @stepone_9555 2 года назад +1

    Congrats sir👍🎉

  • @jaydwarkadhish959
    @jaydwarkadhish959 2 года назад +1

    Sir amazing video super duper

  • @odiacomdeyu.s3148
    @odiacomdeyu.s3148 2 года назад

    You kept your promise... Thank you for that. tq sir

  • @yogeshsharma24
    @yogeshsharma24 2 года назад

    Back to back bhaiya salute to u and me live unacademy pe bhi student huun aapka name yad rkhna bhaiya 😁😁

  • @utkarshsingh405
    @utkarshsingh405 2 года назад

    You kept your promise... Thank you for that... 👍

  • @SantaKakidnapper
    @SantaKakidnapper 2 года назад +1

    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 >?

  • @dainaetishaa5006
    @dainaetishaa5006 2 года назад

    Congratulations vaiya 😊😊😊

  • @smartcoding174
    @smartcoding174 2 года назад

    you are just amazing brother.... thanks for your efforts... 🙏🙏

  • @prayagpatel9136
    @prayagpatel9136 2 года назад +3

    how is topological sort even defined for directed cyclic graphs?

  • @shivam9048
    @shivam9048 Год назад

    Feeling great to reach 100 videos starting in December

  • @iteself_me
    @iteself_me Год назад

    103 ✅completed 👍Liked 1:20

  • @GuruPrasadShukla
    @GuruPrasadShukla 2 года назад

    COngrats on 100 videos

  • @wadhwakashish2044
    @wadhwakashish2044 Год назад

    great efforts sir!! 🫶

  • @mynk_rjpt
    @mynk_rjpt 2 года назад

    Really appreciable work!!!!

  • @demonitachi4491
    @demonitachi4491 Месяц назад +1

    without transposing graph can we just reverse the stack

  • @thecomedystudio4992
    @thecomedystudio4992 2 года назад

    Love Babbar appreciation comment 💯👑

  • @sailendrachettri8521
    @sailendrachettri8521 2 года назад

    Finally we hit century

  • @nishaanand6460
    @nishaanand6460 4 месяца назад

    bhaiya i can also find transpose without using extra loop
    unordered_map adj;
    unordered_map trans_adj;
    for(int i=0; i

  • @laxmankumawat6728
    @laxmankumawat6728 2 года назад

    Finally 🆒😀

  • @jatingarg1897
    @jatingarg1897 2 года назад +1

    I have a doubt .
    When we created revDfs function, we used &adj , when we use &transpose, it shows an error. Why So ?

  • @Aman-fz1ew
    @Aman-fz1ew Год назад

    congratulations ...

  • @sachinrathod8319
    @sachinrathod8319 Год назад

    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.

  • @JohnSmith-uu5gp
    @JohnSmith-uu5gp Год назад

    Just Awesome!!!

  • @harikrushnasuhagiya3925
    @harikrushnasuhagiya3925 2 года назад

    U ARE KING😎😎

  • @vineetkumar2899
    @vineetkumar2899 2 года назад

    awesome bhaiya

  • @d_3_a_d_p_o_o_l
    @d_3_a_d_p_o_o_l 2 года назад +2

    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;
    }

    • @anurag1908
      @anurag1908 2 года назад

      in createList(), for loop should iterate over edges.size() ,not adjList.size().
      correction required:-
      for(int i = 0;i

  • @avishtripathi2587
    @avishtripathi2587 2 года назад +1

    Topological sort can only be used in DAG, how is it working in a graph containing cycle ?

    • @derekspecial1771
      @derekspecial1771 2 года назад +6

      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.

  • @BereniceVirginis
    @BereniceVirginis 10 месяцев назад

    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 🤔

  • @rajmohnani7194
    @rajmohnani7194 Год назад

    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

  • @ayushchoubey9996
    @ayushchoubey9996 2 года назад

    Bhaiya par topological sort to acyclic graphs me hi hoti thi, isme jo aapne example liya hai usme toh cycle hai????

  • @nageshwarmali9631
    @nageshwarmali9631 Год назад

    15 feb 2023 continuesly total 100 completed in 3 month .

  • @umangkumar2005
    @umangkumar2005 Год назад

    or we can reverse stack also instead of graph direction

  • @tushankar6922
    @tushankar6922 Год назад +1

    on 100th one more to go

  • @TheSachinAlam
    @TheSachinAlam 2 года назад

    Legacy 🔥

  • @vinitchaubey6137
    @vinitchaubey6137 2 года назад

    Good explanation

  • @meme_eternity
    @meme_eternity 2 года назад

    why can not we use queue and then there will be no need to reverse the order?

  • @main58507
    @main58507 11 месяцев назад +2

    This Algorithm was purposed by BABA Ranchor Das Samal Das Chancher and the name was inspire by "Prerajulisation" .😂

  • @Tan-mb2nd
    @Tan-mb2nd 6 месяцев назад

    💯💯💯

  • @chhitizekumar1217
    @chhitizekumar1217 2 года назад

    can we use queue instead of stack then there would be no need to take transpose.

  • @TechUprise-by-Jyoti
    @TechUprise-by-Jyoti 2 года назад

    Thank you 😇

  • @AliShair-f7q
    @AliShair-f7q 7 месяцев назад

    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

    • @tusharsharma6518
      @tusharsharma6518 6 месяцев назад

      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)

    • @amaan1180
      @amaan1180 5 месяцев назад

      @@tusharsharma6518 why cant we take queue instead of stack..then we dont need to transpose

  • @khushboobuwade2932
    @khushboobuwade2932 Год назад

    As we pass tanspose we should write &transpose ..but bhaiya wrote adj why ?

  • @KratosProton
    @KratosProton Год назад

    GREAT

  • @Sahil1001
    @Sahil1001 2 года назад

    sir love ur vids

  • @sahilgala1135
    @sahilgala1135 2 года назад

    why we take transpose of edges

  • @sanchitbatra4431
    @sanchitbatra4431 2 года назад

    cyclic graph me topological sorting kaise lag gayi?

  • @d_3_a_d_p_o_o_l
    @d_3_a_d_p_o_o_l 2 года назад

    Toposort only valid in DAG, to bhaiya ne kyu topo sort lgya. guys koi smjha skta h

  • @tunapradhan7571
    @tunapradhan7571 2 года назад

    bhaiya in form.... 🙏🙏🙏

  • @tmiitroorkee1244
    @tmiitroorkee1244 2 года назад +2

    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.

  • @Reehan
    @Reehan 2 года назад

    Aap bhagwan ka kaam kar rhe hai.
    keep doing it.

  • @nishankdeep3084
    @nishankdeep3084 2 года назад

    thank you bhaiya

  • @harshpandey4190
    @harshpandey4190 Год назад +1

    Achievement ++

  • @vivan1852
    @vivan1852 2 года назад

    Century 🤗,
    Consistency++;

  • @khantmadhav4823
    @khantmadhav4823 Год назад +1

    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

  • @kshitijraj1320
    @kshitijraj1320 2 года назад

    🔥🔥🔥

  • @rishav144
    @rishav144 2 года назад

    thanks 🔥

  • @9-1939
    @9-1939 Год назад

    🔥👌

  • @akashjha822
    @akashjha822 2 года назад

    Bhaiya Graph ke thore questions to karwate

  • @sagarsharma007
    @sagarsharma007 2 года назад

    100 ❤🔥

  • @chandradevkushwah932
    @chandradevkushwah932 Год назад

    thank u

  • @solarchat9413
    @solarchat9413 2 года назад

    Century 🏏

  • @multparad
    @multparad 2 года назад

    я дошёл до того что смотрю видос индуса, т.к. не могу найти ничего толкового, каждый алгоритм на каждом сайте выдаёт разный ответ

  • @Pikachu10-19
    @Pikachu10-19 2 года назад

    🥳✨

  • @glaciar_range3270
    @glaciar_range3270 11 месяцев назад

    respect++

  • @soumya1713
    @soumya1713 2 года назад

    Sir next topic ?