How to Find Path in Graphs using Depth First Search | Graphs in Data Structures

Sdílet
Vložit
  • čas přidán 8. 08. 2020
  • Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
    NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the question where we are required to check if a graph has a path from the source vertex to the destination vertex or not. We discuss the constructor of a graph using an Edge class and how a graph is present in memory.
    We solve this question using recursion - Faith and Expectation ,a similar technique which was used while solving the flood fill question in recursion. To watch the solution for Flood Fill, click here: • Flood Fill - Solution ...
    For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
    #pepcoding #graphs #datastructures
    Have a look at our result: www.pepcoding.com/placements
    Follow us on our FB page: / pepcoding
    Follow us on Instagram: / pepcoding
    Follow us on LinkedIn: / pepcoding-education

Komentáře • 120

  • @ankoor
    @ankoor Před 3 lety +34

    One of the best explanations of DFS. I am glad you take time to dry run with diagrams as it helps understand at deeper level. Some coding related CZcamsrs have more views/subscribers but they do not explain half as good as this instructor. Amazing in depth analysis!

    • @Pepcoding
      @Pepcoding  Před 3 lety +3

      Glad you enjoyed it!
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @pranjalchourasia9923
    @pranjalchourasia9923 Před 3 lety +12

    I guess Pepcoding is one of the most underrated channels. Sumeet Sir provides such premium content for free. He should get more views. I have taken DSA courses from other big platforms but their quality and quantity isn't even close to this. Thank You, sir.

    • @Pepcoding
      @Pepcoding  Před 3 lety +9

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

  • @cautioni
    @cautioni Před 3 lety

    I have never had a good grasp of ds algo, but with your videos sir it has been the biggest and only help. SIr please never stop making videos.

  • @loserfruit9663
    @loserfruit9663 Před 3 lety +4

    Sir, you know what is the best thing about pepcoding and you? You guys give significant amount of time to things until we understand the concept clearly,you already know that where we are going to have doubt and you put emphasis on that part and it become crystal clear then whereas in other channel they explain whole thing in just 10 min, that's why pepcoding is best

  • @shoaibakhtar9194
    @shoaibakhtar9194 Před 2 lety

    I am now able to solve the graph questions by myself(for the first time). All credit goes to you, Sir. Best tutorial for graph on the web.
    Thank you so much, Sir

  • @gauravkvtamboli2660
    @gauravkvtamboli2660 Před 2 lety

    Great Explanation!!, the thing I was known about visited was never to visit that vertex, but when I saw Sir's explanation, now I actually/practically got to know with dry run, how that absence of visited array impacted the flow, no one explains this,
    Thanks a lot for such great explanation, even dry run became more strong after watching this video...

  • @93dssagar
    @93dssagar Před 2 lety

    Yeh banda samjhaye aur dimag mein naa utre aisa ho hi nai sakta.....thanks for such a vivid explanation guruji.

  • @_HarshitSharma
    @_HarshitSharma Před 2 lety

    This is pure Gold sir, you simply rock Sumeet sir..Thank you so much for such wonderful content ❤ Specially, the dry run part.

  • @aniruddhadas1778
    @aniruddhadas1778 Před 2 lety

    There is no words to appreciate the effort you are giving to enlighten us every moment

  • @ashyy346
    @ashyy346 Před 7 měsíci

    This is a pure diamond! Thanks a lot sirr

  • @RanveerAllhabadia
    @RanveerAllhabadia Před rokem

    Great Explaination!

  • @nknidhi321
    @nknidhi321 Před 3 lety

    Awesome explanation..❤️

  • @pranshugarg6803
    @pranshugarg6803 Před 2 lety

    ohh... My god such a great explanation........Loved it😍😍😍😍

  • @VikasGupta-ok9lh
    @VikasGupta-ok9lh Před rokem

    The beauty of this course is you know how things are working

  • @nikhilgoyal8340
    @nikhilgoyal8340 Před 3 lety +13

    Amazing analysis Sir. The drawings are really helpful. Keep up the great work.

  • @magic.pencil2.0
    @magic.pencil2.0 Před rokem

    Thank You so much sir for this amazing video. Even though I am from CPP background I get all the points U told 💯

  • @rajatgarg868
    @rajatgarg868 Před 3 lety +5

    Your lectures have always been my goto place for revision... very intuitive explanation, sir...

    • @Pepcoding
      @Pepcoding  Před 3 lety +4

      Glad you liked it !! Share among your peers

  • @nikhilkumarjamwal5322
    @nikhilkumarjamwal5322 Před 2 lety

    Worth watching it.

  • @alpishjain1317
    @alpishjain1317 Před 3 lety +2

    sir great explanation will finish the whole playlist!These videos have really improved my thinking capability.

    • @dark_techyy
      @dark_techyy Před 3 lety

      Thankyou beta!!We r glad my beta😊

  • @vyankateshkulkarni4374

    thanks sir for such a informative lecture :)

  • @mr.naresh3004
    @mr.naresh3004 Před 2 lety

    one of my favorite channel thanks for providing such content sir...

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Keep learning.
      And for better experience and well curated content explore nados.pepcoding.com

  • @45_ritiksharma32
    @45_ritiksharma32 Před 3 lety

    He is first teacher who replies to all student !!
    Great explaination !!

    • @Pepcoding
      @Pepcoding  Před 3 lety +2

      Thank you for the kind words.

  • @deeproy2719
    @deeproy2719 Před 2 lety

    aisa dry run koi nahi karta...thanks Sumit bhaiya

  • @bhargavsai2449
    @bhargavsai2449 Před 3 lety

    loved it

  • @Jasleenjagdev
    @Jasleenjagdev Před 2 lety

    Good explanation

  • @krishnaverma7744
    @krishnaverma7744 Před 2 lety

    This is how I reached to this video....
    Started watching number of island problem,
    then there was a reference to connected graph
    then came to connected graph
    then there was a reference to graph traversal
    so came here
    now here flood fill reference is there and I am going to watch that first :)
    Main Point: I am loving your explanation and not able to leave your video
    This is first time I got courage to even learn about Graphs because of the simple explanation :)
    Thanks :)
    Keep up the good work please.... :)

    • @Pepcoding
      @Pepcoding  Před 2 lety +1

      Glad you love our explanation .
      For better experience sign up on nados.io
      And don't forget to follow us on Instagram instagram.com/pepcoding/

  • @manishbolbanda9872
    @manishbolbanda9872 Před 2 lety

    in case Vertices 0-7 ke range me na hokar ke kuch bhi kuch aur nums hite like 10, 43, 78879, etc any numbers then is case me Map me in verices ki value as key and ArrayList as Value of map ke taur pe used kia jaa sakta hai kya??? please ans .

  • @johnkramer8408
    @johnkramer8408 Před 3 lety +1

    What is the solution of "Cant create generic array of arraylist" ??

  • @jivanmainali1742
    @jivanmainali1742 Před 3 lety +3

    you cant create array of generic classes ,it will give compile time error
    Demo.java:20: error: generic array creation
    do arraylist of arraylist instead

  • @ManishTiwari-ge1wc
    @ManishTiwari-ge1wc Před 3 lety +1

    Excellent explanation.

    • @Pepcoding
      @Pepcoding  Před 3 lety

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review - g.page/Pepcoding/review?rc

  • @harshitkaushik4144
    @harshitkaushik4144 Před 3 lety +1

    Gr8 explanation sir.

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta!
      Will you like to write a few words about us here (www.quora.com/Which-is-the-best-institute-for-coding-in-Delhi)

  • @pranshulkharniwal8146
    @pranshulkharniwal8146 Před 3 lety +1

    😍😍😍nice explanation sir!!

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @veerendrashukla
    @veerendrashukla Před 2 lety

    Super explanation!

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Glad it was helpful!
      Keep learning.
      And for better experience and well organised content visit nados.pepcoding.com

  • @abhishekpatil3132
    @abhishekpatil3132 Před 3 lety +2

    Excellent sirji 👍👍

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Thankyou beta!
      Keep learning and keep loving Pepcoding😊

  • @rishabh7011
    @rishabh7011 Před 3 lety

    Thank you sir 💓

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Most welcome. Please share and subscribe

  • @ProgrammingWithProject

    After the the explanation of this question i am the Jabra fan of sumeet sir

  • @rahulranjan7567
    @rahulranjan7567 Před 3 lety +2

    This guy is a genius when it comes to explaining complex topics. I am feeling better now.
    Good bless you Sumeet Sir.
    Sir wese abb Level up ke question nahi aayenge kya? I mean 10-15 dino se nahi aa rahe hai questions.
    It's a request ki aap please usse pura krr do atleast Dp and Graph of level up.
    Baaki sab badiya hai sir

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thankyou beta,
      I am glad you liked it. If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )
      Aayege beta, jaldi he. Till then, stay tuned.

  • @subhajitghosh8349
    @subhajitghosh8349 Před 2 lety

    great explaination sir

    • @Pepcoding
      @Pepcoding  Před 2 lety +1

      Glad you liked it!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @jakeperalta8135
    @jakeperalta8135 Před 3 lety

    why backtracking step is not there in this?

  • @yashvarshney6761
    @yashvarshney6761 Před 3 lety

    Graph ki playlist porri nahi hai na?? pepcoding.

  • @RahulGupta-xc4fg
    @RahulGupta-xc4fg Před 3 lety +2

    sir, the Dark Mode on website looks pretty awesome :)

  • @sarangr8624
    @sarangr8624 Před 3 lety

    Nicely explained

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @SCRIPTSAG
    @SCRIPTSAG Před 3 lety +1

    Sir recursion ke bad ye sab mst lagta hai

  • @melvinmathew1701
    @melvinmathew1701 Před 4 lety +1

    Why are Graph questions not available in java foundation series on the pepcoding website??

  • @lifecodesher5818
    @lifecodesher5818 Před 3 lety

    sir agar ye visited[src]= true for loop ke bad krte toh koi error aati kya?

    • @Pepcoding
      @Pepcoding  Před 3 lety

      han beta, stack overflow ho jata.

  • @prathamjagga5597
    @prathamjagga5597 Před 3 lety

    sir, i am from PIET college haryana... do you know about our college... how are the placements here?

  • @dhruvsharma7964
    @dhruvsharma7964 Před 3 lety

    Flood fill me visited ko false bhi karte hai hum, yaha kyu nahi kiya?

  • @CodeCraftWithVinayak
    @CodeCraftWithVinayak Před 2 lety

    for loop samj nhi aya
    can some one explain me>
    for(ArrayList edge : graph[src]){ // array ka andar list hai, list liye q nhi loop nhi lagaya and how edge.nbr is valid ?
    }

    • @rahuls8613
      @rahuls8613 Před rokem

      for(Edge edge : graph[src] )
      This is the right syntax.
      We are taking a object / variable 'edge' of class Edge type to access the array list of edges.

  • @PradeepYadav-fg2yg
    @PradeepYadav-fg2yg Před 2 lety +2

    extremely well explained and i wonder how this channel has just 103k subscriber please people share this as much you i am also sharing, help your friends and this channel grow

    • @Pepcoding
      @Pepcoding  Před 2 lety

      These words really mean a lot, for better experience and well organised content sign up on nados.io and start learning.

  • @pradeepbirla1775
    @pradeepbirla1775 Před 2 lety

    Please try to write code in c++ also

  • @amanullahkhan929
    @amanullahkhan929 Před 2 lety

    sir do you have explanation in c++ also if yes please provide link

    • @Pepcoding
      @Pepcoding  Před 2 lety

      Yes, please check c++ video of this same content on nados.pepcoding.com

  • @Only_Nikhil_69
    @Only_Nikhil_69 Před 2 lety

    ArrayList[] graph=new ArrayList[vtces];
    ye line pr "cannot create generic array of arraylist" error aa raha hai

  • @harshpandey7605
    @harshpandey7605 Před 3 lety

    ArrayList[] graph=new ArrayList[vtces];
    Sir please thoda sa ye explain kar dijiye thoda mushkil hora h graphs abhi

    • @Pepcoding
      @Pepcoding  Před 3 lety +2

      arey graph wali first video pehle dekhie na
      yahan se kijie
      www.pepcoding.com/resources/online-java-foundation/graphs

  • @believeinpractical3930

    Nice

  • @hritiksharma3295
    @hritiksharma3295 Před 2 lety +1

    Mohit Tyagi of Computer Science .

  • @harcharansingh1997
    @harcharansingh1997 Před rokem

    ArrayList edge:graph [src]
    how this line produces neighbours

    • @rahuls8613
      @rahuls8613 Před rokem

      for(Edge edge : graph[src] )
      This is the right syntax.
      We are taking a object / variable 'edge' of class Edge type to access the array list of edges.

  • @anjneykumarsingh4461
    @anjneykumarsingh4461 Před 3 lety

    Flood fill m aesa btaye the

  • @shivamkumar-qp1jm
    @shivamkumar-qp1jm Před 3 lety

    Have you not used stack anywhere

  • @cuteangel1726
    @cuteangel1726 Před 3 lety

    Guru ji aap pahle ku ni mile :)

  • @amritgupta5703
    @amritgupta5703 Před 4 lety +3

    Some hardest problems please

    • @Pepcoding
      @Pepcoding  Před 4 lety

      Levelup ki backtracking aane ko hai. Ekdum sahi lagegi

    • @amritgupta5703
      @amritgupta5703 Před 4 lety +1

      @@Pepcoding parallely ek ek que doosre topics ka v daal do :), jo khi usually covered na ho .Thanks a lot

  • @sharathkumar8338
    @sharathkumar8338 Před 3 lety

    isVisited[src]= false kyon nahi kiya?? flood fill mein to kiya tha

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.

    • @subbucs5674
      @subbucs5674 Před 3 lety

      @Sharath Kumar did you get answer for why visited[src] = false is not done ? I have the same query....Can anybody else help us here ?

    • @sharathkumar8338
      @sharathkumar8338 Před 3 lety

      @@subbucs5674 sorry I don't remember it now Did it a month ago right

    • @subbucs5674
      @subbucs5674 Před 3 lety

      @sharath.kumar
      In flood fill, we traverse each cell multiple time, hence we need to set visited[I] = false.
      But, To traverse graph - we need to traverse each node only hence we do not need to set visted[I] = false.

    • @subbucs5674
      @subbucs5674 Před 3 lety

      @Sahil Raj are you trying to say - by not writing visited[I] = false, we are doing some optimization?
      I don't think "not writing visited[i] = false" is an optimization technique... Instead, it is a mandatory code statement to make sure that each node is visited only once in SINGLE traversal - if want to multiple traversal then we need to write visited = false.

  • @anjneykumarsingh4461
    @anjneykumarsingh4461 Před 3 lety

    Sir path print krna chaiye n

  • @mayur_madhwani03
    @mayur_madhwani03 Před 2 lety +1

    Aap neighbour ke pichhe neighbour aapke pichhe too much fun

  • @dark_techyy
    @dark_techyy Před 3 lety +2

    Or ye mai 10:58 pe ja rha hu flood fill dekhne😑😂

  • @rupesshmetra13
    @rupesshmetra13 Před 3 lety

    Generic array creation error🤕

  • @lakshayrastogi7640
    @lakshayrastogi7640 Před 2 lety

    Has anyone attempted this Q in c++?

  • @999ggod
    @999ggod Před 4 lety +1

    Typo in name

  • @knightrec869
    @knightrec869 Před 3 lety +1

    Peepcoding doesn't have - ve comment.
    5 🌟

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      keep motivating, keep learning and keep loving Pepcoding😊

  • @varunvishwakarma3422
    @varunvishwakarma3422 Před 2 lety

    neighbor badmas h sir, sath me le k nahi ja rha!

  • @neharikasrivastav7465
    @neharikasrivastav7465 Před 3 lety

    sir please make one is cpp also

  • @anjneykumarsingh4461
    @anjneykumarsingh4461 Před 3 lety

    Saare not 1

  • @syrym_the_professor
    @syrym_the_professor Před 3 lety

    All good, but is it english? I can not understand, sorry

  • @ghanibhai1630
    @ghanibhai1630 Před 2 lety

    recursive solution without using visited space
    import java.io.*;
    import java.util.*;
    public class Main {
    static class Edge {
    int src;
    int nbr;
    int wt;
    Edge(int src, int nbr, int wt){
    this.src = src;
    this.nbr = nbr;
    this.wt = wt;
    }
    }
    public static boolean has_path(ArrayList[] graph,int sr,int de,int l){
    if(l==graph.length){
    return false;
    }
    if(sr==de){
    return true;
    }
    boolean a=false;
    for(int i=0;i