Kosaraju Algorithm | Strongly connected components in a graph

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.ย. 2020
  • This video explains the Kosaraju algorithm which is used to find all the strongly connected components in a graph.We can even use this algorithm to find if the given graph is strongly connected or not.I have shown the concepts of strongly connected components in the beginning of the video and then explained some properties of graph which we can use to find the strongly connected components.I have explained the kosaraju algorithm using simple DFS and stack.This is a 3 step process.The first step is to traverse the graph using DFS and then push the nodes in stack.The second step is to find transpose of the graph, that is, reverse all the edges in the graph.The third step is to pop nodes one by one from stack and make DFS calls to find the nodes in a strongly connected component.I have also shown why the kosaraju algorithm logic works using the transpose graph logic.At the end of the video, I have explained the code walk through.CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
    ========================================================================
    Join this channel to appreciate our effort /\ and to get access to perks:
    / @techdose4u
    INSTAGRAM : / surya.pratap.k
    SUPPORT OUR WORK: / techdose
    LinkedIn: / surya-pratap-kahar-47b...
    WEBSITE: techdose.co.in/
    TELEGRAM Channel LINK: t.me/codewithTECHDOSE
    TELEGRAM Group LINK: t.me/joinchat/SRVOIxWR4sRIVv5...
    =======================================================================
    CODE LINK: gist.github.com/SuryaPratapK/...
    USEFUL VIDEOS:-
    Prims Algorithm: • Prims algorithm | MST ...
    Kruskals Algorithm: • Kruskals algorithm | C...

ความคิดเห็น • 226

  • @adityaojha2701
    @adityaojha2701 3 ปีที่แล้ว +73

    The unique thing about your explanations is you not only explain algorithm but also explain how to implement that using dry runs which are great.

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +1

      Thanks

    • @adityaojha2701
      @adityaojha2701 3 ปีที่แล้ว

      @Callen Emory do not fall into this whosoever reading this comment. It's a spam.

    • @adityaojha2701
      @adityaojha2701 3 ปีที่แล้ว

      @Mark Josiah 😂😂 trap

  • @himanshu2149
    @himanshu2149 3 ปีที่แล้ว +11

    Fluent English + Beautiful Presentation + Superb Examples + Best Explanation = TECH DOSE

  • @vaibhavsingh-fu1vg
    @vaibhavsingh-fu1vg 3 ปีที่แล้ว +1

    Loved the premise !! That's what made your explanation different from other videos that I came across!

  • @battlecrusecruse9155
    @battlecrusecruse9155 2 ปีที่แล้ว +2

    the best explanation over the internet
    this guy must be protected at any cost.

  • @iamakifislam
    @iamakifislam 3 ปีที่แล้ว +5

    You are the boss. You have absolutely clear my concept of SCC. Your channel deserves 1 Million ❤️ Thank you for the video.

  • @abhilashsulibela1414
    @abhilashsulibela1414 3 ปีที่แล้ว +1

    This is amazing! a very clear flow of thought. Thank you for making this & I request you to please continue to make such high-quality videos

  • @svworld01
    @svworld01 3 ปีที่แล้ว +3

    Here I found the best explanation of this algorithm. Thank You :)

  • @mayukhbhowmik934
    @mayukhbhowmik934 2 หลายเดือนก่อน +1

    Superb Content, Just spellbound after watching the tutorial.

  • @mayankchauhan6680
    @mayankchauhan6680 3 ปีที่แล้ว +5

    You are an amazing teacher. I mean everything taught by you seems very simple even if it's not.

  • @ClashWithSwap
    @ClashWithSwap 3 ปีที่แล้ว +28

    Loved the explanation. Could you make one on bridges and articulation points too? You make graphs easy!

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +6

      Thanks. Those are the upcoming topics 😁

    • @shubhamagarwal2998
      @shubhamagarwal2998 3 ปีที่แล้ว

      @@techdose4u thanks bhaiya

    • @Learner010
      @Learner010 3 ปีที่แล้ว

      @@techdose4u thanks

  • @shuvadiproy5154
    @shuvadiproy5154 ปีที่แล้ว

    Best and easiest explanation....And feeling proud of that Kosaraju Algorithm was discovered by an Indian .

  • @sahilnegi2789
    @sahilnegi2789 3 ปีที่แล้ว

    Sir your content is so amazing that after watching your lecture I thought it is so simple. thanks again .
    keep uploading this amazing content . you

  • @Cruz0e
    @Cruz0e 2 ปีที่แล้ว +3

    Beautiful explanation, I usually have hard times to understand tutorials in Indian accent. So when I googled I had to turn pages to find one that isn't Indian. First I watched that other video (with not Indian accent) on the subject. But it was horrible. Then said I give a try, and I chose this video.
    I have to say your explanation is beautiful, clear and easy to understand, the accent is barely noticeable. I like it! Great job!
    (Obviously. Liked and Subscribed.)

  • @charikgoyal5612
    @charikgoyal5612 3 ปีที่แล้ว +2

    bhai aap gajab ho like truly god of algorithms 🙌🙌

  • @ytuser659
    @ytuser659 3 ปีที่แล้ว +3

    Was waiting for this. Thank you!

  • @manavkumarjaiswal2734
    @manavkumarjaiswal2734 3 ปีที่แล้ว +2

    Just got the perfect reason which I was eagerly searching for
    Great explaination
    adios

  • @letsdoeverythinginoneweek9398
    @letsdoeverythinginoneweek9398 3 ปีที่แล้ว

    Thnk u sir mazaa aa gayi
    itna acha explanation Nahi Suna mena .
    Keep more videos .

  • @bablushaw6856
    @bablushaw6856 2 ปีที่แล้ว

    It feels good when I see your video in TH-cam result list of my problem. Nothing else to try then.

  • @goblin1390
    @goblin1390 3 ปีที่แล้ว +1

    Graph algorithm ans especially implementation was a nightmare.Thanks for very easy explanation. Please make more videos related competitive programming topics.

  • @vijaykumarlokhande1607
    @vijaykumarlokhande1607 3 ปีที่แล้ว +2

    why I love the explanation? simple bcoz clear voice, dark background, and content flow.

  • @indiansoftwareengineer4899
    @indiansoftwareengineer4899 ปีที่แล้ว

    Thanks a lot Surya bro, your videos are gems, awesome work.

  • @ankitsoni3388
    @ankitsoni3388 3 ปีที่แล้ว +2

    Awesome bro, would like to meet you sometime. It's really hard to take out time from your daily schedule and create such amazing content. Thanks alot!!

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว

      Welcome. Sure 🙂

  • @deathicon3405
    @deathicon3405 3 ปีที่แล้ว +21

    In both the examples you showed, you started from a node which in the SCC with outgoing edge,
    What will happen if it was an ingoing edge, like what will you in your first DFS?

    • @PRANAVMAPPOLI
      @PRANAVMAPPOLI ปีที่แล้ว

      You can do a DFS that we use for unconnected components and use a common stack for all dfs call. That will works

  • @SurajKumar-bw9oi
    @SurajKumar-bw9oi 2 ปีที่แล้ว

    If I would be a teacher I would like to teach like you. Great explanation.

  • @abhinaygupta
    @abhinaygupta 3 ปีที่แล้ว

    Great explanation. Converted Kosaraju in simple dfs.

  • @ashreetpatnaik9735
    @ashreetpatnaik9735 3 ปีที่แล้ว +2

    Beautiful explaination ❤️🔥🔥🔥 please don't stop we will support you 😊

  • @vojtechrozhon362
    @vojtechrozhon362 3 ปีที่แล้ว +1

    Absolutely amazing work!

  • @sharuk3545
    @sharuk3545 3 ปีที่แล้ว +1

    One of the best Solution on entire platform.... Thnk u SOoooooo much broooooo make more videos

  • @mohnishsinghbhamra
    @mohnishsinghbhamra 3 ปีที่แล้ว +1

    Love to see graph algorithms in your channel

  • @togiraikonoka9664
    @togiraikonoka9664 2 ปีที่แล้ว

    love it! lowkey saved my life ngl

  • @EngWorld-nr2ww
    @EngWorld-nr2ww 3 ปีที่แล้ว +1

    best explanation of kosaraju till now..

  • @puneethj9920
    @puneethj9920 3 ปีที่แล้ว

    This is amazing and the best explanation.

  • @sandutozlovanu9353
    @sandutozlovanu9353 2 ปีที่แล้ว

    Best video ever !

  • @abhijitmishra7736
    @abhijitmishra7736 2 ปีที่แล้ว

    Great Video

  • @georgemullarjampana
    @georgemullarjampana 3 ปีที่แล้ว +6

    underrated video

  • @piyushlohiya1977
    @piyushlohiya1977 3 ปีที่แล้ว

    Explanation is so good👍

  • @abheetsingh9938
    @abheetsingh9938 3 ปีที่แล้ว +1

    if were a teacher in our college , the attendance in the classroom would be 100% .....Thanks a lot for your hard work :)

  • @danym-98
    @danym-98 2 ปีที่แล้ว +1

    Great explanation!

  • @SUJOYPAULJOBS
    @SUJOYPAULJOBS 3 ปีที่แล้ว +1

    khub valo video ta....i puro buje giyechi vi...thank you bro.

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว

      Emni korte thako👌🏼

    • @SUJOYPAULJOBS
      @SUJOYPAULJOBS 3 ปีที่แล้ว

      @@techdose4u OK BRO

  • @karanveersingh5535
    @karanveersingh5535 2 ปีที่แล้ว

    U made it so simple 🔥

  • @syeedtalha1550
    @syeedtalha1550 3 ปีที่แล้ว

    Thank you so much

  • @RahulKumar-si5dp
    @RahulKumar-si5dp 3 ปีที่แล้ว +1

    Enjoyed a lot and...also learned ...
    You made this understand so easy ...

  • @UtkarshSingh-qn9xu
    @UtkarshSingh-qn9xu 3 ปีที่แล้ว +1

    Instead of pushing the elements in the stack during backtracking, we can directly push the element as we are moving ahead, in that case, we won't even require to reverse the graph. Secondly, a point was missing here. While doing a DFS, if we are unable to reach every node, we must again do the DFS on the remaining ones. The example taken satisfied the approach but it can have many more cases. Still, I could think all this because I could understand what you explained in this video. Thanks. Do consider these points and let me know if I am going wrong.

    • @spatil689
      @spatil689 ปีที่แล้ว

      Even I am having the same doubt can we do this?

  • @tlado5370
    @tlado5370 3 ปีที่แล้ว +1

    Thank you, this was very helpful!

  • @hsetareh
    @hsetareh 3 ปีที่แล้ว

    Excellent explanation.

  • @SuperLucasGuns
    @SuperLucasGuns 3 ปีที่แล้ว

    this was sensational

  • @nirmalbabu9570
    @nirmalbabu9570 3 ปีที่แล้ว +1

    thanks a bunch. The visual dry run was very helpful

  • @ssshukla26
    @ssshukla26 3 ปีที่แล้ว

    Really good explanation. Thank you.

  • @yangsiyu007
    @yangsiyu007 3 ปีที่แล้ว +1

    Super video! I applauded for $2.00 👏

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว

      Thanks for your support ❤️

  • @raysk4798
    @raysk4798 3 ปีที่แล้ว +1

    Thanks for the clear explanation!

  • @agynbolatov7018
    @agynbolatov7018 3 ปีที่แล้ว

    thank you!

  • @Naaz-2002
    @Naaz-2002 3 ปีที่แล้ว +1

    Thank u so much, you made it so easy to understand!

  • @ashutoshkumar4267
    @ashutoshkumar4267 3 ปีที่แล้ว +1

    Thank you for making Graphs so easy

  • @than0s869
    @than0s869 2 ปีที่แล้ว

    nice explanation sir... :)

  • @kongzilla2897
    @kongzilla2897 3 ปีที่แล้ว +1

    Loved it :)

  • @srinivaskarthik1692
    @srinivaskarthik1692 2 ปีที่แล้ว +2

    Everything is perfect !!
    Except to the fact that you could have shed some idea on why there was a usage of Stack here ( I could have traversed from any node , why any particular order from stack ?? )... . which would make us applaud for the genius Kosaraju.

    • @techdose4u
      @techdose4u  2 ปีที่แล้ว

      That is because if you jump from one SCC to another and then if you reverse edges, you can't jump from the same SCC to other one where you could have been able to jump prior to reversing.

    • @srinivaskarthik1692
      @srinivaskarthik1692 2 ปีที่แล้ว

      @@techdose4u Thank you, i know the reason but few others in the comments had doubt on the usage of stack , hence I mentioned it would be great if it was explained in the video.

  • @Learner010
    @Learner010 3 ปีที่แล้ว +1

    very well explained!

  • @suryakiran2970
    @suryakiran2970 ปีที่แล้ว

    Excellent

  • @akshaycharjan6384
    @akshaycharjan6384 3 ปีที่แล้ว +1

    Thanks a Ton :)

  • @amgadshrief7215
    @amgadshrief7215 หลายเดือนก่อน

    you are awesome keep going bro

    • @techdose4u
      @techdose4u  หลายเดือนก่อน

      thanks :)

  • @HarshKumar-nh6be
    @HarshKumar-nh6be 3 ปีที่แล้ว +2

    Very very great explanation sir❤❤

  • @suharajsalim4549
    @suharajsalim4549 3 ปีที่แล้ว +1

    Wow Thanks a lot :)

  • @fahadisrar2195
    @fahadisrar2195 3 ปีที่แล้ว +1

    that was Helpful..Thanks!!

  • @mdimranhosen6674
    @mdimranhosen6674 2 ปีที่แล้ว +1

    You deserve this: 💚:

  • @mahipalsingh-yo4jt
    @mahipalsingh-yo4jt 3 ปีที่แล้ว +1

    how are we able to know the particular node from which the first dfs is starting.? Because if we start dfs from any node another than 0 than we will have to make manual jumps and we will not be able to push all the elements to the stack without manually verifying that all the nodes have been visited...

  • @umarteachestechwith2others803
    @umarteachestechwith2others803 2 ปีที่แล้ว

    Thank you for amazing explanation but a little correction here. In case of undirected graph we call component a "connected component" not strongly connected component. SCC term is specifically used for directed graph if there is directed path from v to u and u to v.

  • @anuragagarwal9617
    @anuragagarwal9617 2 ปีที่แล้ว +1

    The explanation is great and very helpful to me, thanks @TECH DOSE

  • @vikashdhania2970
    @vikashdhania2970 2 ปีที่แล้ว

    👍👍👍👍

  • @vedantshinde2277
    @vedantshinde2277 ปีที่แล้ว

    Best explanation I've come across! Would the algorithm work if we started with a random node in the graph for step1 instead of '0'?

  • @musicnition1063
    @musicnition1063 3 ปีที่แล้ว

    Hi, at Minute 16:18 I check the vertex of the transposed graph. I don't go to three, because 3 is already traversed. Then I go to node 6 and write 6 to the SCC of 4. WHY? Don't I have to WAIT until I "see" that both 4 and 6 are in the SAME SCC? How do you see that?

  • @kunalsoni7681
    @kunalsoni7681 3 ปีที่แล้ว +1

    Amazing session 💞🥰 I learn alot from this algorithm. Thanking you so much sir

  • @kishantiwari3221
    @kishantiwari3221 3 ปีที่แล้ว +1

    Thank You Sir!

  • @ritikmathur7469
    @ritikmathur7469 3 ปีที่แล้ว +1

    Nice!

  • @anshuofficial166
    @anshuofficial166 2 ปีที่แล้ว

    why we used stack, we can use for loop at second time DFS?

  • @ratneshpal6026
    @ratneshpal6026 3 ปีที่แล้ว +2

    @ TECH DOSE, very informative video.
    There is a small suggestion....
    While showing the code...please zoom your code editor so that it is properly visible.
    Thanks.

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +4

      I will try to make the font larger from next time.

  • @pythonwithsi
    @pythonwithsi 2 ปีที่แล้ว

    thank you bro.

  • @piyushlohiya1977
    @piyushlohiya1977 3 ปีที่แล้ว

    Can anyone tell me do we really need stack we can just take transpose and do dfs traversal the one which are not visited :++cnt

  • @ivanvachilia4183
    @ivanvachilia4183 3 ปีที่แล้ว +1

    Thanks!

  • @samirpaul2
    @samirpaul2 2 ปีที่แล้ว

    🙌🔥🔥🔥🔥👍✨✨👌

  • @maheshvoleti6990
    @maheshvoleti6990 3 ปีที่แล้ว +1

    what if we start our first dfs with node in second ssc?

  • @aanuraag83
    @aanuraag83 3 ปีที่แล้ว +1

    Thank you : )

  • @ashishgor2163
    @ashishgor2163 ปีที่แล้ว

    Thank you sir

  • @footballfanatics007
    @footballfanatics007 2 ปีที่แล้ว +1

    Great explanation

  • @mysteriesandfacts4u22
    @mysteriesandfacts4u22 2 ปีที่แล้ว +1

    Best explanation

  • @manjus3
    @manjus3 3 ปีที่แล้ว

    Hi @tech dose, thanks for this excellent video on Kosaraju's algorithm. Just had a question: After you have identified all the strongly connected components, how do you find the in_degree and out_degree of an entire SCC? Thanks!

    • @abhishekshankar1136
      @abhishekshankar1136 3 ปีที่แล้ว

      you can maintain an array of vector for each strongly connected component, for each vertice u , for each v in adjacent of u you can do indegree of v ++ and outdegree of u ++ , time complexity will be O ( V+E )

  • @theghostwhowalk
    @theghostwhowalk 3 ปีที่แล้ว +1

    Amazing. Thanks for this video. If one has to detect if there is cycle in Directed graph, is Kosaraju algo way to go? We can’t do normal DFS.

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +3

      You can use same logic of finding strongly connected components. DFS with visited should work. We could have also used coloring.

  • @naman_goyal
    @naman_goyal 3 ปีที่แล้ว +1

    very nice explanation

  • @sujan_kumar_mitra
    @sujan_kumar_mitra 3 ปีที่แล้ว +1

    Hey, what if instead of reversing the edges, we reverse the stack and perform dfs.. Will it generate wrong output?

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +1

      No it won't work. On reversing edges, the connecting edge between SCC is reversed. If you take SCC as just a single node then the graph will be a DAG. Our goal here is to detect when we move from one SCC to another. For that reason, you will require that edges are reversed so that you can't traverse more than 1 SCC using DFS only once. You need to manually make the jump.

  • @mustafa-ahmed-dev
    @mustafa-ahmed-dev ปีที่แล้ว

    thank you

  • @soumambanerjee1816
    @soumambanerjee1816 3 ปีที่แล้ว +1

    Awesome

  • @beingSenpai
    @beingSenpai ปีที่แล้ว

    can any one tell me
    its a dumb question but please help Me
    what if they given the graph in the inverse way then as per kosaraju if we reverse again we go from 0 to 7

  • @shantamshrestha2070
    @shantamshrestha2070 3 ปีที่แล้ว +1

    Sir your videos are wonderful. Please create videos on Word Break I and II problems on leetcode. Shall be grateful

  • @rahulchudasama9363
    @rahulchudasama9363 3 ปีที่แล้ว

    Awesome explaination,
    What is the application of this algo?

  • @mustafa-ahmed-dev
    @mustafa-ahmed-dev ปีที่แล้ว

    what is the blackboard you are using

  • @ritikgoyal6087
    @ritikgoyal6087 2 ปีที่แล้ว +4

    Can we interpret this question as we have to found all the cycles and the respective value of nodes present in them and at last we will consider all those nodes as seperate connected components which are not involved in any cycle.

    • @techdose4u
      @techdose4u  2 ปีที่แล้ว

      Yes. SCCs are cyclic.

  • @hardikagarwal7652
    @hardikagarwal7652 3 ปีที่แล้ว +3

    I don't get why the first DFS was needed?

    • @gourharisharma9373
      @gourharisharma9373 3 ปีที่แล้ว

      so that you could store elements in stack, because after reversing the edges you cannot go from one component to another so stack will help you to find the node of next component.

  • @yelnil
    @yelnil 3 ปีที่แล้ว +2

    Does it matter which node we start doing DFS during the first DFS?

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +3

      No. Because you can do manual jumps in DFS1 as well.

  • @kirtigera2225
    @kirtigera2225 3 ปีที่แล้ว +1

    thankew sir....

  • @khilanpatels
    @khilanpatels 3 ปีที่แล้ว

    which software are you using to draw?

  • @NoReelOnlyReal
    @NoReelOnlyReal 2 ปีที่แล้ว +1

    Explanation is very clear and understandable , altoghuh I had a question , can't we run the DFS on the original graph from last vertex and find the storongly connected components in each iteration ?