6.9 Detect Cycle in Undirected Graph | Data Structures and Algorithms

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 พ.ย. 2024

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

  • @jianingzhuang104
    @jianingzhuang104 4 ปีที่แล้ว +23

    I like this type of concise, to-the-point videos!

  • @noorfatima8524
    @noorfatima8524 5 ปีที่แล้ว +13

    i got the concept within 5 minutes and its all because of u. thank you..
    u nailed it.

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

    Your algorithm is very succinct and efficient. More importantly, your explanation is extremely intuitive, logical and easy to follow. Thank you!

    • @GopalSingh-gx5jm
      @GopalSingh-gx5jm ปีที่แล้ว

      some test cases are not passing..what is wrong in this code?
      bool isCycle(int V, vector adj[]) {
      int flag[V];
      for(int i=0;i

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

    Mam you are greate teacher (we all like you)

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

    thank you very much Jenny, we love you.

  • @vlceon
    @vlceon 4 ปีที่แล้ว +1

    very nice explained, sending thanks from Czech Republic

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

    Absolutely brilliant and concise explanation. Thank you.

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

    Nice idea to use the three colors with a BFS traversal to avoid keeping track of the parent 👍

  • @continnum_radhe-radhe
    @continnum_radhe-radhe ปีที่แล้ว +1

    Thank you mam 🔥🔥🔥

  • @rajangarg8748
    @rajangarg8748 5 ปีที่แล้ว +9

    Can you also explain the solution when we have to print all the cycles in an undirected graph?

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

    Helped a lot

  • @kuladeepmazumdar346
    @kuladeepmazumdar346 5 ปีที่แล้ว +1

    Thank you so much maam.

  • @arpitshah9591
    @arpitshah9591 5 ปีที่แล้ว +1

    nice explanation ...keep making such videos

  • @Mayank-hg7rr
    @Mayank-hg7rr 4 ปีที่แล้ว

    great work JENNY

  • @prateekkumarpanda9251
    @prateekkumarpanda9251 4 ปีที่แล้ว

    Nice explanation 😘😘😘

  • @246amishakumari7
    @246amishakumari7 3 ปีที่แล้ว

    thanks ma'am !!

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

    I am paying more attention to this lady's expressions than the lecture...

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

    Is this approach applicable for directed graph ?

  • @VickyKumar-fk1rr
    @VickyKumar-fk1rr 5 ปีที่แล้ว +1

    well explained

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

    excellent

  • @diptadip7113
    @diptadip7113 5 ปีที่แล้ว

    super explanation mam!!

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

    Samjh v aya aur maja b

  • @amruthajm7127
    @amruthajm7127 4 ปีที่แล้ว +6

    can u give the pseudocode for the same ..like upload it in the coment or description it would be very helpful..thank you :)

  • @rohitdixit1617
    @rohitdixit1617 5 ปีที่แล้ว

    simply amazing!

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

    If there is a other single egde from a to a will it be a considered a cycle

  • @shahzaibsheikh3525
    @shahzaibsheikh3525 5 ปีที่แล้ว +1

    Keep it up mam

  • @ShaliniSingh-xc5rn
    @ShaliniSingh-xc5rn 5 ปีที่แล้ว +1

    Thnku mam

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

    I need to find the shortest cycle using bfs. how to do so?

  • @parimal7684
    @parimal7684 4 ปีที่แล้ว

    when we were visiting A then you marked flag[A] =1 after exploring all adjacent nodes but after that you were marking flag =1 before exploring that and that may cause ..it will not detect loop on it self means if the path exist to itself please go through it and if i am getting wrong somewhere please tell me

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

    does this also work in case of disconnected graphs?

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

      It does, you just have to make sure to run this several times until all nodes have been visited (all nodes have a label of 1 or 0). So if you run this once and you still have nodes with -1 label left, then you restart this algo from the next -1 node.

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

      @@ansismaleckis1296 got it thanks!

  • @amiriqbal1689
    @amiriqbal1689 4 ปีที่แล้ว

    So good..studies with beauty ! XD

  • @ss-xh3hf
    @ss-xh3hf 4 ปีที่แล้ว

    correct the order of playlist of dsa

  • @muzafferckay2609
    @muzafferckay2609 4 ปีที่แล้ว

    Thanks a lot. Is the condition which is if any vertex finds its adjacent vertex with flag 0 then it contains a cycle valid for directed graph?

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

    Excellent. Could you please suggest how to print one such cycle

    • @Anonymous-2-0-1-2
      @Anonymous-2-0-1-2 5 ปีที่แล้ว

      you can use "DFS method" and keep track parent_map of each node.
      when you found cycle then, use the parent_map to print all item in cycle .

  • @subhadipmaity3253
    @subhadipmaity3253 4 ปีที่แล้ว +1

    Mam, can you please explain the code by making another one video, please

  • @lifecodesher5818
    @lifecodesher5818 4 ปีที่แล้ว +7

    E is a cheater! Whole this time D kept thinking that E is his adjacent vertex only but E was also the adjacent vertex of B! My condolences for D. Rot in hell B and E!!

    • @shiwamjaiswal9653
      @shiwamjaiswal9653 4 ปีที่แล้ว +1

      Lol thank god i have been single my entire life xD.

    • @lifecodesher5818
      @lifecodesher5818 4 ปีที่แล้ว

      @@shiwamjaiswal9653 haha

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

    Great explaination but for GFG pass
    will need to take disconnected graph in account
    public boolean isCycle(int v, ArrayList adj) {
    // Code here
    Queue q = new LinkedList();
    int f[] = new int[v];
    Arrays.fill(f, -1);

    for(int j = 0; j < v; j++) {
    if(f[j] == -1){
    q.add(j);
    f[j] = 0;
    while(!q.isEmpty()){
    int curr = q.remove();
    f[curr] = 1;
    for(int i = 0; i < adj.get(curr).size(); i++){
    int vi = adj.get(curr).get(i);
    if(f[vi] == 0){
    return true;
    } else if(f[vi] == -1) {
    q.add(vi);
    f[vi] = 0;
    }
    }
    }
    }
    }
    return false;
    }

  • @AbhiRam-ei3cm
    @AbhiRam-ei3cm 2 ปีที่แล้ว

    How to watch this class infrent of you😍

  • @sanskarsrivastava8016
    @sanskarsrivastava8016 4 ปีที่แล้ว

    how u will do it with adjacency matrix and reduce the complexity from o(n)2

  • @karanmane3421
    @karanmane3421 5 ปีที่แล้ว +1

    Hello ma'am , can you please share the program of the same?

  • @padmakaki1936
    @padmakaki1936 5 ปีที่แล้ว

    How can you put d and e in queue after c .. it's not possible right .. i will be d,e,c then 😶

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

    Hayeeeeeeeeeeeeeeeee, Thank YOU

  • @shrad6611
    @shrad6611 5 ปีที่แล้ว +1

    can u please explain the code as well in java. I don't able to understand the code SO please help me

  • @hemantmarve3674
    @hemantmarve3674 4 ปีที่แล้ว

    Is it work for only connected Graph?

    • @mdizrail792
      @mdizrail792 4 ปีที่แล้ว

      Yes you have to loop over vertix in disconnected graph.

  • @08_mech_tharun42
    @08_mech_tharun42 4 ปีที่แล้ว

    Mam pls tell us the program regarding this concept pls.......mam

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

    I have you give subtitle 😭🔥

  • @tranuctrinh9405
    @tranuctrinh9405 4 ปีที่แล้ว

    why do not you use DFS for detecting cycle in an undirected graph?

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

    Ok , so where are the disjoint sets

  • @prakashzode968
    @prakashzode968 4 ปีที่แล้ว

    Teacher main 12th main ho Maine computer science ke badle biology liya. Hai Kya main 12 ke bad computer engineering Kar sakta hoon aap comment karke bato

    • @subhadipmaity3253
      @subhadipmaity3253 4 ปีที่แล้ว

      Of course bro NO problem, if you have PCM in 12th then you can do whatever you want in the engineering field.

  • @Rahul.r.r_p
    @Rahul.r.r_p 10 หลายเดือนก่อน

    Day 67

  • @sounakbhowmik2841
    @sounakbhowmik2841 4 ปีที่แล้ว +1

    Maam does this method work if there is a back edge to the previous node from the current node? I want to mean, say if there are [1,2] and [2,1] or say, [1,1] //here there is an edge from one node to itself. What happens then?

    • @YashArora721
      @YashArora721 4 ปีที่แล้ว +1

      Back edge concept doesn't count in undirected graph as you already have an edge from a to b and b to a. So back edge doesn't help

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

    why couldnt i see this video before ;-(

  • @abhijeetrai4324
    @abhijeetrai4324 4 ปีที่แล้ว

    This doesn't work for graphs with self Loop

  • @preptshala
    @preptshala 4 ปีที่แล้ว +1

    Mam Hindi me bhi video banaiye

  • @RahulKumar-zf4ps
    @RahulKumar-zf4ps 5 ปีที่แล้ว +1

    this is true for a connected component not for a graph, if a graph has more than one connected component then it may return false result

    • @mukeshanandmanjhi2318
      @mukeshanandmanjhi2318 5 ปีที่แล้ว +4

      No it will work u will just have to maintain a for loop and send a bfs whenever u encounter a -1

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

    thx

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

    G 251

  • @michaelmwenda7110
    @michaelmwenda7110 4 ปีที่แล้ว

    If you teach automata theory, plz drop a video and we will appreciate

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

    Also topological sort for undirected graph doesnt make sense

  • @prateekkumarpanda9251
    @prateekkumarpanda9251 4 ปีที่แล้ว

    Wowwwww

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

    Who can give me a code this solution

  • @preptshala
    @preptshala 4 ปีที่แล้ว +1

    Mam thorha Hindi wallo par bhi dhyan diyaa kariye

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

    Pls stop asking for code! Have some decency! If you cant write your own code then you have to go back to beginners class.