Depth first search | DFS | Depth first traversal

This video explains a very important concept for graph which is depth first search also known as depth first traversal,i.e., DFS or DFT. The concept is explained for both the UNDIRECTED as well as DIRECTED graph in easiest way possible to help you grasp concepts easily. The code is explained at last after the theoretical concepts and the CODE LINK is present below. 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 :)
CODE LINK: gist.github.com/SuryaPratapK/...

Пікірлер: 82

  • @ravigadadi6207
    @ravigadadi62073 жыл бұрын

    My TECHnical knowledge is getting over DOSEd by watching your channel. Thank you Man!

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome :)

  • @patilsoham
    @patilsoham4 жыл бұрын

    I must say, it is a perfect resource to learn DFS. Keep explaining code also for each and every problem. Thanks for your efforts. Eagerly waiting to see grow your channel to 6 digit family.

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks bro :)

  • @dipper0yawn
    @dipper0yawn2 жыл бұрын

    It took me some time to implement this in C, I nearly started pulling my hair out. Without your tutorial, I would have been completely lost, such an elegant solution.

  • @shivamchauhan2673
    @shivamchauhan26734 жыл бұрын

    You are amazing, your channels needs a boom. Unlike other, your method of explaining is the best.

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks :)

  • @shrirampareek
    @shrirampareek4 жыл бұрын

    This is the simplest explanation and implementation of dfs! Great work

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks

  • @Randomguy-zv3tv
    @Randomguy-zv3tv3 жыл бұрын

    the best explanation ive ever seen,thanks man

  • @beyondallreason-du4pq
    @beyondallreason-du4pq4 ай бұрын

    best explanation!!! thank you

  • @gethunews9299
    @gethunews92994 жыл бұрын

    Great work brother. Respect for your efforts. Thank you so much for bringing thjs kinda content upon running.

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Welcome :)

  • @gnanajeyam6259
    @gnanajeyam62593 жыл бұрын

    Everyone can learn recursion and DFS from you 😄 great work brother 👏

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks

  • @eshankaur9659
    @eshankaur96593 жыл бұрын

    At 11:29 in undirected graph what happen if we choose C vertex as starting vertex that has no path to reach other vertices ??

  • @kumarpriyansh4238
    @kumarpriyansh42384 жыл бұрын

    Awesome Work . I have seen many of your video. I am a beginner but everything is very well explained. Good work.

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks

  • @AtulDislay
    @AtulDislay4 жыл бұрын

    You content deserve more subscribers

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Share the video to help find some,that will be great :P How shameless of me :D

  • @AtulDislay

    @AtulDislay

    4 жыл бұрын

    @@techdose4u already done😁

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    @@AtulDislay Thanks bro :)

  • @awakashsinha9926

    @awakashsinha9926

    4 жыл бұрын

    I think yeah he deserves

  • @soumensinha305
    @soumensinha3054 жыл бұрын

    Please try to make more videos, Your explanation is crisp and very easy to understand.

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks bro. I make videos whenever i get time from office :)

  • @yashwanthsai2460
    @yashwanthsai24603 жыл бұрын

    Hi..could you please help me with the explaintion of time complexity of DFS approach explained in the video

  • @musicnition1063
    @musicnition10633 жыл бұрын

    With the DFS you cannot return/read the max depth of a graph, can you?

  • @chandanbanerjee3721
    @chandanbanerjee37213 жыл бұрын

    this was excellent...can you do one dfs by iterative method too?

  • @jamilurrehmanamini4878
    @jamilurrehmanamini48782 жыл бұрын

    subscribed , you channel is gold

  • @techdose4u

    @techdose4u

    2 жыл бұрын

    Thanks 😊

  • @ManpreetSingh-ki5yh
    @ManpreetSingh-ki5yh2 жыл бұрын

    what if we are at a vertex which has only incoming edges?

  • @HarshKumar-nh6be
    @HarshKumar-nh6be3 жыл бұрын

    Really great😊

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks 😃

  • @jiteshkumar3112
    @jiteshkumar31124 жыл бұрын

    why g[s][i] is called in dfs function as it 'll give a vertex value and not index... and if i consider it vertex value than y you passed 0 intially because maybe 0 will be not present

  • @aesthetic_vibes_404

    @aesthetic_vibes_404

    4 жыл бұрын

    Code wasent compiled of mine too

  • @lakshmikanthk442
    @lakshmikanthk4423 жыл бұрын

    Is backtracking is necessary .?as we are already mking visited=1

  • @ManpreetSingh-ki5yh
    @ManpreetSingh-ki5yh2 жыл бұрын

    Hi, Did I miss anything or the example is not accurate to justify the use of stack. If on backtracking we are just visiting vertex, then why keep them in stack at all? I got confused in this and I think may be the example here is not making use of stack but there could be case where stack can be used when all neighbouring vertex are not visited yet.

  • @69upasonabiswas88
    @69upasonabiswas883 жыл бұрын

    sweet and simple explanation..

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks :)

  • @sumanmandal5952
    @sumanmandal59522 жыл бұрын

    Why we use stack here , what is the need for backtracking, we can print dfs by just visited array? Can u explain

  • @kuchalaggyan2502
    @kuchalaggyan25023 жыл бұрын

    what is Morris Transversal? There is no video available in your playlist. can you explain me a little bit.

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    I will make it once start the topic :)

  • @praveennandham2933
    @praveennandham29333 жыл бұрын

    Thanks bro :)

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome bro :)

  • @vidishasharma6795
    @vidishasharma67954 жыл бұрын

    Please also showcase the output in your videos for better understanding and visual result of the code.

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    I think the code is self explanatory. In this video I dint explain it but recently I have been including code explanation in videos.

  • @852_harshitkumar6
    @852_harshitkumar63 жыл бұрын

    The code here is for undirected graphs?

  • @sugat7206
    @sugat72063 жыл бұрын

    I can see now how you are so genius , You are Itachi (11:36) 🤩😂😂😂 btw very helpful video, Thank you sir.

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    😂

  • @khakr01
    @khakr014 жыл бұрын

    A follow-up question, what would be the flow if we begin from C which has no outwards edges in case of the directed graph?

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    The example i explained covered all the nodes from the starting point. The graph could have been multi-component or it could have started at C as well. The answer changes according to question. If you are required to do DFS from starting point C then only 1 node will be traversed but if you are asked to visit all the nodes in a graph starting from C then you need to use a loop for all nodes and perform DFS (i think i have used the loop for traversal in code.check it once). If you don't use a loop then some nodes might get left. So, it all depends on objective of question. I think you got it now.

  • @khakr01

    @khakr01

    4 жыл бұрын

    @@techdose4u Thank you for the explanation. Your videos are great for learning. I am happy to see your number of subscribers going up. Keep teaching. Humble request, please upload your code to Github for better access and reference. Thanks again

  • @kshamadalal
    @kshamadalal2 жыл бұрын

    Thanks!

  • @techdose4u

    @techdose4u

    2 жыл бұрын

    Welcome

  • @080somyasrivastava6
    @080somyasrivastava64 жыл бұрын

    Does the complexity changes if we apply iterative implementation using stl stack.?

  • @prateekjhabak5414

    @prateekjhabak5414

    3 жыл бұрын

    NO if we count the stack memory. I think the only case when recursive may fail when we have n>10^6 or 10^7 something due to stack overflow,then iterative will definitely work.

  • @adityajoshi3922
    @adityajoshi39223 жыл бұрын

    it's array of vectors right?

  • @ManinderSingh-xr6ir
    @ManinderSingh-xr6ir2 жыл бұрын

    code is not working,can you please share this code.

  • @venkateswararaodevisetti8684
    @venkateswararaodevisetti86843 жыл бұрын

    Bro Its very useful and informational Now I got confidence that, I can crack any DSA coding interview But. I need help in system design Do u have any reference for it

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks. No

  • @ishitaamod5109
    @ishitaamod51092 жыл бұрын

    can u provide the code in java also?

  • @ghoshdipan
    @ghoshdipan3 жыл бұрын

    where is the staack implementation

  • @thesafdarkhan007
    @thesafdarkhan0072 жыл бұрын

    Don't you think your concept was based on stack implementation but code is based on recursion?

  • @abhaytiwari6411
    @abhaytiwari64114 жыл бұрын

    bro i am study in class 11 with commerce in future can i get a job in big giants company as software engineer plz give road map for me

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    There are openings for commerce people as well, but they won't hire you as a software engg but only as a finance advisor, finance manager, HR, economist etc. If you wanna become a software or hardware engg then you should take science for future atleast. If you need any more advice then feel free to ask :)

  • @abhaytiwari6411

    @abhaytiwari6411

    4 жыл бұрын

    I take IT in class 11th . it can help me to get as soft engineer

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Bro you need to pursue BCA/Btech for software engg job as far as i have seen.

  • @abhaytiwari6411

    @abhaytiwari6411

    4 жыл бұрын

    thanksgiving for clearing my doubts

  • @randomrandom316

    @randomrandom316

    4 жыл бұрын

    @@abhaytiwari6411 Have you taken Maths alongside Commerce? If you have then you can taken BSc IT for bachelors and then get into IT companies. Even if you haven't taken Maths but are interested in it and programming I would advise that you continue to work on your CS skills, it will surely payoff.

  • @yashikagarg4044
    @yashikagarg40443 жыл бұрын

    Time complexity of this code pls...

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    This is simple solution with O(EV) if I remember correctly. You can optimize by coloring or stack to get O(E+V)

  • @sayantaniguha8519

    @sayantaniguha8519

    2 жыл бұрын

    ​ @TECH DOSE The code using stack hasn't been taught by u

  • @vamsikrishna1092
    @vamsikrishna10924 жыл бұрын

    This DFS doesn't work disconnected graph .

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    If you know the count of vertices then you can iterate over them to cover multiple components.

  • @navinchainani4721
    @navinchainani47213 жыл бұрын

    Why u write this statement while(t--)?

  • @sayandey4307

    @sayandey4307

    2 жыл бұрын

    T denotes no of test cases I

  • @spetsnaz_2
    @spetsnaz_23 жыл бұрын

    Code Link : techdose.co.in/dfs/

  • @venkateswararaodevisetti8684
    @venkateswararaodevisetti86843 жыл бұрын

    Java code is below ============== import java.util.Iterator; import java.util.LinkedList; public class Graph { int nodes; LinkedList edges[] ; boolean visited[]; public Graph(int nodes) { this.nodes = nodes; edges = new LinkedList[nodes]; visited = new boolean[nodes]; for(int i=0;i

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    👍🏼

  • @sumitgarudkar5542
    @sumitgarudkar55423 жыл бұрын

    the code you mentioned in the description is very diff from wt u explain and the fact is that you didn't show your code running . It's a SCAM!

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    I think you can implement it easily :) I didn't use to show code in the past so that you learn to implement. But I have been showing code since March 2020.