Lecture 88: Cycle Detection in Undirected Graphs || Using BFS and DFS

  Рет қаралды 146,307

CodeHelp - by Babbar

CodeHelp - by Babbar

Күн бұрын

Пікірлер: 164
@gargkapil
@gargkapil 2 жыл бұрын
this entire series is much much much better then so many paid courses.
@muzammilaltafmulla
@muzammilaltafmulla 5 ай бұрын
You forgot 'very very' before those 'much'...
@thinkverse94
@thinkverse94 2 жыл бұрын
Thanks, Babbar bro for the superb explanation and your enthu :) Here just I wanna add a point, that is much easier to understand to detect loop:- // if the number of visited nodes in any adjacency list is >=2 then there is a cycle. // no need for extra parent data structure Sample code which passed all the test cases:- bool isCyclicBFS(int node, unordered_map &visited, unordered_map &adjList) { queue q; q.push(node); visited[node] = true; while(!q.empty()) { node = q.front(); // counter for already visited nodes int cnt = 0; //traversing the adjacency list for(int i: adjList[node]) { if(!visited[i]) { q.push(i); visited[i] = true; } else { cnt++; } } q.pop(the ); // if the number of visited nodes in any adjacency list is >=2 then there is a cycle. if(cnt >= 2) return true; } return false; }
@samsmith3961
@samsmith3961 2 жыл бұрын
how does it work i am not able to comprehend the concept used here , wont count be considered 0 everytime the loop makes another iteration
@thinkverse94
@thinkverse94 2 жыл бұрын
​@@samsmith3961 very simple, if the number visited adjacent nodes >=2 for a node ... that means one is a parent and at least one node will be there which is visited but not a parent ... that's how you co-relate
@thinkverse94
@thinkverse94 2 жыл бұрын
@@samsmith3961 see the count is initialised 0 before calculating the adjacent nodes for a node, it will continue to count until all the adjacent are covered for a particular node, that's how we can track the number of visited adjacent nodes, and at the end we checking is it >= 2 or not
@hinalvakharia2744
@hinalvakharia2744 2 жыл бұрын
will it work for DFS?
@KushalSharma-d3q
@KushalSharma-d3q Жыл бұрын
​@@hinalvakharia2744if adj list has >=2 elements with visited==true that simply means it has a loop so its a condition for a loop whatever approach u go with
@shalinisaini3787
@shalinisaini3787 15 күн бұрын
Thankyou Bhaiya for this amazing course
@barnikroy5244
@barnikroy5244 2 жыл бұрын
at least you kept your word to complete this course .........salute once more
@samsmith3961
@samsmith3961 2 жыл бұрын
yeh course kaafi underrated hai... i hope people would soon pay attention to a treasure trove of a channel like yours!!!! kudos to you and pls keep up the good work.
@hameedmulani21
@hameedmulani21 Жыл бұрын
Its very good course with Complete Dry Run of Example that is what I want
@vaibhavrathod9674
@vaibhavrathod9674 Жыл бұрын
Finally I have watched this video 3 times, now I properly understand how this works.. Thank you so much Bhaiya...... Love you from Gujarat💖💖
@ShouryaPant
@ShouryaPant 2 жыл бұрын
Finaaly Our Beloved Babbar Bhaiyya Is Back Bass Ab Consistency Bhi Apnr Babaar Bhaiyya Ki phle jaise vapis Aajye Maza Aajayega🙂🙂🤩🤩
@AdityaRaj05
@AdityaRaj05 2 жыл бұрын
Sir provide complete notes 15-16 and from 41 to above also Ur notes is too good sir . Plz provide us so tat we can revise easily.
@crazykidda5831
@crazykidda5831 Жыл бұрын
very nice lecture....I can't believe I could have understand all these when I started. But u are too good.
@darshanpatel9131
@darshanpatel9131 10 ай бұрын
bool isCyclicDFS(int node,int parent,unordered_map &visited,unordered_map &adj) Here why are we passing the adj list with pass by reference method ? Since there is no relation with the changing the values present in the adj list.
@muhammadsuleman8936
@muhammadsuleman8936 Жыл бұрын
Lecture was super amazing i recomment this playlist to everyone>> Amazing content zbr10
@vmstudy9965
@vmstudy9965 5 ай бұрын
Bhaiya mjaa aa gya. Aisi dry run krk btaya kro 🎉❤. Ekdm chumeshwar tha 😅
@prashantbirajdar9271
@prashantbirajdar9271 2 жыл бұрын
bhut achaa ++ hai bhiya subkuch samaj ayaa nice bhaiya thanks..love u bhaiyaa....
@alexrcrew1975
@alexrcrew1975 2 жыл бұрын
-- --
@abhijeetbasfore6816
@abhijeetbasfore6816 2 жыл бұрын
bhaiya BFS algo use jab apne kara parent ke liye different ds nhi banake queue ho jata na
@beinghappy9223
@beinghappy9223 2 жыл бұрын
Thank u bhaiya Best video on Cycle Detection available on KZbin ❤
@shubhammalhotra7244
@shubhammalhotra7244 Жыл бұрын
For every visited vertex v, if there is an adjacent u. Such that u is already visited & u is not the parent of v. So, cycle in the graph is present/
@nishankdeep3084
@nishankdeep3084 2 жыл бұрын
thank you bhiaiya saare concept ache se clear hue bhaiya concept learn++
@ShivamGupta-qn7lj
@ShivamGupta-qn7lj Жыл бұрын
We can also use vector adj, but it shows runtime error 16:25
@ankitchavhan
@ankitchavhan Ай бұрын
Well explained!! Just one feedback... Please highlight your mouse pointer with some color.
@jhordd52
@jhordd52 2 жыл бұрын
bhaiyaa plzz video length badhado and good to see you back again just questions krvado bhaiya jese pehle topics mai krvaye hai baaki sab op hai aapke hmare liye itne efforts bhi kam nhi hai
@RohitSingh-hc8yi
@RohitSingh-hc8yi Жыл бұрын
loving this course bhaiya
@harshpandey4190
@harshpandey4190 Жыл бұрын
Lecture is Amazing ++
@vishalgarna4580
@vishalgarna4580 Жыл бұрын
Samajh aaya gaya bhaiya
@rachit_joshi
@rachit_joshi 5 ай бұрын
Thank You So Much BHRATA SHREE !!!!!!!
@apoorvaron46
@apoorvaron46 Жыл бұрын
for next time, Please do dry run with small examples
@syedmuhammadabdullah2920
@syedmuhammadabdullah2920 6 ай бұрын
Thankyou so much for successfully wasting my time
@mancunianswagger3668
@mancunianswagger3668 2 жыл бұрын
Finally video aayi ek❤ Daalo bhaiya daal do saari do mahine me placements hain krwaado tayaari fir mail me thankyou jarur bhejenge promise 🤞😅
@salmankhader1258
@salmankhader1258 Жыл бұрын
plz discuss time and space complexity as well
@amitnagdev7061
@amitnagdev7061 2 жыл бұрын
In Simple Words, agar koi ek node k do 'mai-bap' mile toh samaj jana k voh ek cyclic component hai uss graph ka.😄
@barkhagupta5237
@barkhagupta5237 10 ай бұрын
😂😂😂😂I willl remember this logic @amitnagdev7061
@tayyab.sheikh
@tayyab.sheikh Ай бұрын
Point!
@mr.writer2903
@mr.writer2903 7 ай бұрын
Now, i am realize just see whole logic and write code by yourself. it's possible that you find better code 🙃.
@slowDrive4
@slowDrive4 2 жыл бұрын
you can just use an extra set instead of object or dict
@vanshgoyal1356
@vanshgoyal1356 2 жыл бұрын
Actually I've a doubt !! Here "src" is basically "i" and we are doing "q.push(src)" so are we considering that the graph will always contains a 0 as a vertex and will always run from 0 to V. Please correct me if I'm wrong. Thank you ❤❤
@sanipatel1272
@sanipatel1272 2 жыл бұрын
Yes bro we are starting vertex from 0 to its value.
@anuragpandey8165
@anuragpandey8165 2 жыл бұрын
Boht achaa lecture........... par consistency chahiye babbar bhai
@GauravHaritas
@GauravHaritas Жыл бұрын
bhaiya k editor ko bhi DSA aa gya gaya hoga ab tk to itni videos dekh dekh k
@utkarshsingh1457
@utkarshsingh1457 2 жыл бұрын
Thanks for the video bhaiya... ❤️🔥
@bite091_jamee7
@bite091_jamee7 2 жыл бұрын
amazing bhaiya
@iamvishnuranjan
@iamvishnuranjan 2 жыл бұрын
Bhaiya plz end this course before placement 😭😭😭
@VivekSingh-xg5mn
@VivekSingh-xg5mn 2 жыл бұрын
best videos on DSA and algo for sure on internet
@AmanKumar-io3ev
@AmanKumar-io3ev 7 ай бұрын
but bhaiya what will happen if nodes are not 1,2,3 despite of a ,b ,c
@subratamandal2924
@subratamandal2924 6 ай бұрын
Yes in that case indexing will be a problem. You can do arr['a'-char] to store
@haiderali0801
@haiderali0801 2 жыл бұрын
amazing bhaiya......
@heighlights012
@heighlights012 Жыл бұрын
bhai code kaha pe milega ye vala mera problem de raha code link mai sirf lec 44 tak hi hai
@Learnprogramming-q7f
@Learnprogramming-q7f 7 ай бұрын
Thank you Bhaiya
@PrakharSaini-zw8nz
@PrakharSaini-zw8nz 2 жыл бұрын
Thanx for this video and your unbeatable efforts..
@sounaksaha1455
@sounaksaha1455 2 жыл бұрын
maza aa gaya bhaiya
@SatyamKumar-x6m1l
@SatyamKumar-x6m1l 4 ай бұрын
sir eska code kaha hai jo link hai usma bass tree tk ka hi code haii graph aur bakki lecture ka code ka link kaha hai
@MrKalwar
@MrKalwar 8 ай бұрын
bahut badhiya bhaiya!!
@footballcreativeeverywhere260
@footballcreativeeverywhere260 Жыл бұрын
Jai hind ❤️🇮🇳
@adityavishwakarrma514
@adityavishwakarrma514 2 жыл бұрын
Ho jayega course complete complete++
@IndianGao
@IndianGao 2 жыл бұрын
are you fine bhaiya ji please notes bhi send kar dijiye 14-15 and 41 se aage ka
@apoorvyadav3378
@apoorvyadav3378 2 жыл бұрын
Bhaiya is back 🔥🔥🔥
@shivkumar-og4ow
@shivkumar-og4ow 2 жыл бұрын
thank you bhaiya .. for your hard work . Doing a good job
@KCOYASH
@KCOYASH Жыл бұрын
completed and thanks for the video
@SFAbhi9642
@SFAbhi9642 2 жыл бұрын
@Love Babbar bhaiya which keyboard do use for programming
@piyushkumar-wg8cv
@piyushkumar-wg8cv 2 жыл бұрын
For better experience, watch in 1.25x speed. Meanwhile me who was already watching the video in 1.5x :- 🌝
@yutubegaming5340
@yutubegaming5340 5 ай бұрын
1.75
@alokranjan3185
@alokranjan3185 2 жыл бұрын
Thanks bhaiya ,wait is over
@ks-xh4fq
@ks-xh4fq 5 ай бұрын
Why parent of neighbour = front ? Line 24
@saujanyashukla5483
@saujanyashukla5483 2 жыл бұрын
Good to see u back bhaiya keep the consistency up again ❤️
@itzheavem4451
@itzheavem4451 2 жыл бұрын
last community post added last week he said we will be consistent now abhi es video mei bola hai ki 13 tarik k baad se consistent ho jayenge toh hisab sidha sa hai ab pehle wali baat nhi reh gyi hai course mei videos ki length v choti kr di gyi hai jabki feedback v diya tha last video mei. or padhane k style se pta lag rha hai wo pehle wale enthusiasm se nhi padhaya ja raha hai
@saujanyashukla5483
@saujanyashukla5483 2 жыл бұрын
@@itzheavem4451 u are right bro
@grandson_f_phixis9480
@grandson_f_phixis9480 5 ай бұрын
Thank you very much sir
@vishalgarna4580
@vishalgarna4580 Жыл бұрын
Acha nahi bahut accha 😊😊
@Deepak-um1zq
@Deepak-um1zq Жыл бұрын
nice lectures❤
@tejasshaha6629
@tejasshaha6629 2 жыл бұрын
We trust you bhaiya ❤
@prashantaarya3852
@prashantaarya3852 2 жыл бұрын
awesome explanation
@akankshapandey9773
@akankshapandey9773 2 жыл бұрын
Thanku so much sir , sir pls series complete kr dijiye 2 month me placement hai pls sir 🙏
@jimarrafi5881
@jimarrafi5881 2 жыл бұрын
Bhai, Please make video on String Matching. It will be really helpful to us.
@amishapandey6875
@amishapandey6875 Жыл бұрын
Well explained!
@KratosProton
@KratosProton 2 жыл бұрын
great explaination
@iteself_me
@iteself_me Жыл бұрын
133 ✅completed 👍Liked 5:3
@ayushgupta1881
@ayushgupta1881 Жыл бұрын
Thanks a lot bhaiya
@abhinavtiwari6405
@abhinavtiwari6405 Жыл бұрын
Bohot acha lga ❤️
@fazerugbrug439
@fazerugbrug439 2 жыл бұрын
superb
@diyatoliya9067
@diyatoliya9067 6 ай бұрын
Loved it!!
@govindnair3135
@govindnair3135 2 жыл бұрын
thamks a lot bhaiyya
@B-NikhilRichhariya
@B-NikhilRichhariya Жыл бұрын
bhot achhaa
@cse_29_abdulshariqkalim15
@cse_29_abdulshariqkalim15 2 жыл бұрын
Bro please make videos regularly
@yashasvic2429
@yashasvic2429 Жыл бұрын
Thank You bhai 👍
@adamyasharma_0135
@adamyasharma_0135 9 ай бұрын
best!
@chandrasubhashinithakran8323
@chandrasubhashinithakran8323 2 жыл бұрын
// code for this lecture #include #include #include bool iscyclicBFS(int src, unordered_map &visited, unordered_map adj){ unordered_map parent; parent[src]=-1; visited[src]=1; queue q; q.push(src); while(!q.empty()){ int front = q.front(); q.pop(); for(auto neighbour: adj[front]){ if(visited[neighbour]==true && neighbour!=parent[front]){ return true; } else if(!visited[neighbour]){ q.push(neighbour); visited[neighbour]=1; parent[neighbour]=front; } } } return false; } bool iscyclicDFS(int node,int parent, unordered_map &visited, unordered_map &adj){ visited[node]=true; for(auto neighbour: adj[node]){ if(!visited[neighbour]){ bool cycledetected=iscyclicDFS(neighbour, node,visited,adj); if(cycledetected) return true; } else if(neighbour != parent){ //cycle present return true; } } return false; } string cycleDetection (vector& edges, int n, int m) { // create adjacency list unordered_map adj; for(int i=0;i
@dEviL_bIsWaJiT
@dEviL_bIsWaJiT 2 жыл бұрын
Best dsa course ever.:) #dsabusted
@TANYAGOSWAMI-m3g
@TANYAGOSWAMI-m3g 11 ай бұрын
thanks bhaiya
@focus.placement5589
@focus.placement5589 2 жыл бұрын
thanks bhaaiya
@iamvishnuranjan
@iamvishnuranjan 2 жыл бұрын
Plz end this course before placement 😔😔😔😔😔
@S4UR4BH4
@S4UR4BH4 Жыл бұрын
kya baat!
@shubhamkhare26
@shubhamkhare26 2 жыл бұрын
Great video...
@sheetalmittal6240
@sheetalmittal6240 2 жыл бұрын
Best DSA course
@sukhjitsingh959
@sukhjitsingh959 2 жыл бұрын
We are present Babbar B
@063himanshumishra4
@063himanshumishra4 2 жыл бұрын
Bhaiya moj kr diii
@mysticmuskan3529
@mysticmuskan3529 Жыл бұрын
Thank u sir
@GuruPrasadShukla
@GuruPrasadShukla 2 жыл бұрын
sahi tha bhaiya thx
@sarthakjain1824
@sarthakjain1824 Жыл бұрын
Much easier approach with lesser space complexity class Solution { public: bool bfs(int i,vector adj[],unordered_map &visited){ queue q; q.push(i); while(!q.empty()) { int temp=q.front(); visited[temp]=true; if(q.size()>1) { if(q.front()==q.back()) return true; } q.pop(); for(auto j: adj[temp]) { if(!visited[j]){ q.push(j);} } } return false; } bool isCycle(int V, vector adj[]) { unordered_map visited; for(int i=0;i
@voicechanger3635
@voicechanger3635 Жыл бұрын
TLE mar rha hai ye code to
@KhushiKavya-py1yj
@KhushiKavya-py1yj 4 ай бұрын
i was not consistent but i will try to be now
@nikhilsingla4107
@nikhilsingla4107 2 жыл бұрын
best course in DSA
@collegebkchodi6687
@collegebkchodi6687 2 жыл бұрын
Bhaiya problem practice krao graph ka
@vedantdeshmukh4949
@vedantdeshmukh4949 2 жыл бұрын
Bhaiya ab quality++ aur consistency++ krlo bs 🥹
@itzheavem4451
@itzheavem4451 2 жыл бұрын
agle ne bol toh diya firse 13 tarikh k baad se consistent ho jayege. wese he jese har video mei bola jata h lekin 2 mahine se consistency ka koi tikhana nhi h
@raghavattri9449
@raghavattri9449 2 жыл бұрын
Bhaiya new course ki announcement kab hogi😅
@chintaphaniramavaibhav3714
@chintaphaniramavaibhav3714 2 жыл бұрын
babar bhai please provide us with notes and code bhaiyya
@shresthkaushik6636
@shresthkaushik6636 Жыл бұрын
🙏🙏🙏
@amantarar9077
@amantarar9077 2 жыл бұрын
Bhaiya course kab khtm hoga ? Date btado
@arpit7618
@arpit7618 Жыл бұрын
awesome
@mohdshaban2824
@mohdshaban2824 2 жыл бұрын
LOVE
Lecture 89: Cycle Detection in Directed Graphs || Placement Series
18:30
CodeHelp - by Babbar
Рет қаралды 96 М.
Lecture 87: DFS Traversal in Graph || C++ Placement Series
14:18
CodeHelp - by Babbar
Рет қаралды 157 М.
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,5 МЛН
MIT Introduction to Deep Learning | 6.S191
1:09:58
Alexander Amini
Рет қаралды 737 М.
AIR 6 vs AIR 600 after 6 years of graduating IIT
1:12:27
Harkirat Singh
Рет қаралды 34 М.
G-11. Detect a Cycle in an Undirected Graph using BFS | C++ | Java
20:19
G-19. Detect cycle in a directed graph using DFS | Java | C++
17:22
take U forward
Рет қаралды 251 М.
Lecture 90: Topological Sort ( Using DFS ) || Placement Series
20:09
CodeHelp - by Babbar
Рет қаралды 109 М.
Lecture 93: Shortest Path in Undirected Graphs || C++ Placement Series
19:52
CodeHelp - by Babbar
Рет қаралды 90 М.