Pre and Post visited Times in DFS | Graphs | Pre and Post numbers

Поділитися
Вставка
  • Опубліковано 23 січ 2025

КОМЕНТАРІ • 17

  • @KnowledgeCenter
    @KnowledgeCenter  4 роки тому +1

    *** CLARIFICATION: At 5:40, I said all the edges will go from Left to Right. It was for DFS Tree edges only i.e., edges we used in DFS. There will be Back edge going from right to left.
    In DAGs there will be no Edges from Right to left.

  • @MrSun8080
    @MrSun8080 4 роки тому +2

    What a nice video! I really wish to see the video of using this algorithm to solve actual problems

  • @digantgupta168
    @digantgupta168 4 роки тому +2

    Make videos on Tarjans algo ! Along with LeetCode example of any SC Components.
    Also thank you for your work !

  • @user-yk7mn7we2i
    @user-yk7mn7we2i Рік тому +1

    you're a legend

  • @RajeshKumar28sep
    @RajeshKumar28sep Рік тому

    These pre and post timings refer to the timings the node is added (pre) to the stack and then removed (post) from the stack. Makes things easier and need no memorization! Try to visualize the stack and you are all set!

  • @bhattibhatti708
    @bhattibhatti708 3 роки тому

    How to undirected graph start and end time

  • @dhruvankadavala568
    @dhruvankadavala568 3 роки тому +1

    Nice explanation....

  • @naidusunny2744
    @naidusunny2744 4 роки тому +1

    Can you please add the lecture no also so that it will be easy to view videos in order, youtube playlist shows videos in random order

    • @KnowledgeCenter
      @KnowledgeCenter  4 роки тому +1

      First 6-7 lectures relating to theory are in order. After that ordering is not maintained for Leetcode examples. Definitely needs some proper ordering for those examples as well. Will have a look.

  • @AmanVerma-or3ge
    @AmanVerma-or3ge 4 роки тому +1

    Can you please share python code for this.

    • @KnowledgeCenter
      @KnowledgeCenter  4 роки тому

      Take the Python code for DFS from this github: github.com/KnowledgeCenterUA-cam/Graphs/blob/master/DFS
      Ignore the DFS_it(). Just take DFS_rec(), and add the 2 time stamps before and after dfs. So it will be like this:
      def DFS_rec(self, s, visited):
      visited[s] = True
      self.time += 1
      self.pre[s] = self.time
      print(s)
      for u in self.m_adj[s]:
      if not visited[u]:
      self.DFS_rec(u, visited)
      self.time += 1
      self.post[s] = self.time
      And in the main dfs: add the lists pre and post, and variable time to self.
      That should do.
      References:
      github.com/KnowledgeCenterUA-cam/Graphs/blob/master/DFS
      github.com/KnowledgeCenterUA-cam/Graphs/blob/master/Pre_Post_Visit_Times_DFS

  • @sanskritinannore7209
    @sanskritinannore7209 2 роки тому +1

    Here's the Java code for your reference:
    class Graph{
    private int m_V;
    private List[] m_adj;
    private int time;
    Graph(int v){
    m_V = v;
    m_adj = new LinkedList[v];
    for(int i=0;i

  • @RajKumar-vi9ht
    @RajKumar-vi9ht 3 роки тому +1

    Thanks