Lecture47: Detect & Remove Loop in Linked List [Approach Discussion + Optimised Implementation]

  Рет қаралды 231,040

CodeHelp - by Babbar

CodeHelp - by Babbar

Күн бұрын

In this Video, we are going to solve important questions based on Linked List.
There is a lot to learn, Keep in mind “ Mnn bhot karega k chor yrr apne se nahi hoga ya maza nahi aara, Just ask 1 question “ Why I started ? “
[For 20% Discount ] Visit Coding Ninjas: bit.ly/3cfdKTe
Discord Server Link: / discord
Course Flow: whimsical.com/dsa-4-placement...
Slides Link: drive.google.com/file/d/1dp1V...
Code Links: github.com/loveBabbar/CodeHel...
Questions Links:
- Detect & Remove Loop in Linked List: bit.ly/3rSdTDo
Do provide you feedback in the comments, we are going to make it best collectively.
Connect with me here:
Instagram: / lovebabbar1
Twitter: / lovebabbar3
Telegram Group Link: Love Babbar CODE HELP
telegram.me/lovebabbercodehelp
My Editor: rishu.rsing...
Intro Sequence: We have bought all the required Licenses of the Audio, Video & Animation used.
Timestamps:
00:00 - Introduction
02:17 - Promotion
03:09 - Approach #1 - Detect Cycle
06:05 - Code Approach #1 - Detect Cycle
14:40 - Approach #2 - Floyd Cycle Detection
17:10 - Code Approach #2 - Floyd Cycle Detection
21:31 - why this works ?
25:30 - Approach #3 - find starting node of Loop
28:35 - Proof - why this works ?
34:40 - Code Approach #3 - find starting node of Loop
37:42 - Approach #4 - Remove Loop from Linked List
38:48 - Code Approach #4 - Remove Loop from Linked List
45:40 - Merging all Logic - to detect & remove Loop
48:10 - Adding NULL Checks
49:33 - Homework and Summary
#DSABusted #LoveBabbar

Пікірлер: 429
@torus151
@torus151 2 жыл бұрын
Mathematical proof of Flyod's Loop detection was Awensome
@gouravmuchhal1985
@gouravmuchhal1985 Жыл бұрын
@@rapidtech9592 yup dude you are fucking right
@bishalchatterjee745
@bishalchatterjee745 2 жыл бұрын
After watching your videos, it feels that the most easiest part of coding after printing "Hello World" is Linked List..😄😄😄😄
@nikunjjain2382
@nikunjjain2382 2 жыл бұрын
Bhaiya mathematical proof of Floyd algo is op😎.. Finally got the point why we are actually doing this..And the way you explained in super awesome
@BEESaiShivam
@BEESaiShivam Жыл бұрын
Started this course back in june 2022 , now have reached 120th video but simulatenously revising concepts, again and this time understading his videos in more depth and using it as a revision to improve TC of my solutions.
@mayanksinha7612
@mayanksinha7612 Ай бұрын
😊😊😊😊😊😊😊😊😊😊😊
@rudrakshairon1087
@rudrakshairon1087 2 жыл бұрын
By far the best course on DSA , ty for your consistency and hard work .
@GrahamGroot69
@GrahamGroot69 2 жыл бұрын
Great lectures🔥🔥. Unlike other inconsistent youtubers who only claim to complete a course in this this time.
@fazerugbrug439
@fazerugbrug439 2 жыл бұрын
thank you for being consistent and delivering the high-quality course.
@aditya_0524
@aditya_0524 2 жыл бұрын
Bro please check if this code runs in your compiler or not, because the loop is present statement is not running in my compiler. #include #include #include using namespace std; class Node{ public: int data; Node * next; Node(int data){ this->data = data; this->next = NULL; } }; void insertAtHead(Node* &head, int d){ //creating new node which then will be our first node-> Node* node2 = new Node(d); node2->next = head; head = node2; } void insertAtTail(Node* &tail, int d){ //creating new node which then will be our first node-> Node* node2 = new Node(d); tail->next = node2; tail = node2; } void insertAtPosition(Node* & tail, Node* & head, int position, int d){ //Using below condition we are inserting the given element at start, // and then updating the head-> if(position == 1){ insertAtHead(head, d); return; } Node* temp = head; int count = 1; while(count < position-1){ temp = temp->next; count++; } //if we are inserting at the end, then this condition will update the tail-> if(temp->next == NULL){ insertAtTail(tail, d); return; } //Creating a node for d-> Node* nodeToInsert = new Node(d); nodeToInsert->next = temp->next; temp->next = nodeToInsert; } void print(Node* & head){ Node* temp = head; while(temp != NULL){ cout
@fazerugbrug439
@fazerugbrug439 2 жыл бұрын
@@aditya_0524 try to run this in online compiler as it is an infinite loop
@itskaaryan7
@itskaaryan7 Жыл бұрын
It's my humble request to everyone watching the vidoes , please do like his video because he is putting his effort and providing us such a valuable content , that too free of cost, so we can atleast appreciate him by pressing the like button. I hope everyone uderstands what i am trying to convey. 👍👍
@b.chinrhea
@b.chinrhea Жыл бұрын
You have pretty much covered everything in linked lists , salute to you hard work
@suvigyabasnotra7378
@suvigyabasnotra7378 2 жыл бұрын
44:25 At this moment I finally realized why rest of the distance in the loop is A. Prior to that, I was really perplexed with how you found that out. Understood it Not because of how you spoke in that moment but noticed that A = [ (k no. of cycles)*(each Cycle) ] - B . which is also the rest of the distance.
@ManishSingh-vr2yj
@ManishSingh-vr2yj Жыл бұрын
And i got that better after raeding ur cmmnt...😅
@piyushaaryan869
@piyushaaryan869 Жыл бұрын
what if value of k =0.5??
@salmankhader1258
@salmankhader1258 Жыл бұрын
BUT IN REST OF THE DISTANCE WE DONT HAVE TO INCLUDE K NUMBER IF CYCLES. I STILL DIDNT GOT, PLZ CLEAR IT,
@lakshsinghania
@lakshsinghania Жыл бұрын
yes , A is not the distance of each cycle C its some K times we are covering that C and finally we found out the meeting point of fast and slow ( the remaining becomes A)
@unboxtheuniverse5336
@unboxtheuniverse5336 2 жыл бұрын
Yee baaatttt 🔥💥 Har dinn aapke liye ijjat badte hi jaa rhi he , bhagwan na ban jao DSA ke 🔥😂 Bhaiya plz *"5 Month Internship Strategy Series"* laaO... 2nd year walo ke liye with your DSA Busted course as resource 😃🤩
@SanketMali-xd9oo
@SanketMali-xd9oo 29 күн бұрын
Today everyone has made education a business but sir you have given this course for free ,it is much better than paid courses. Thank you sir❤
@AnonymousUser98771
@AnonymousUser98771 27 күн бұрын
kitne paid course leliye tune?
@gurvindersingh8592
@gurvindersingh8592 2 жыл бұрын
Thank you sir, for providing such a explained lecture on this topic. Because of it, I was able to solve detect cycle in a LL, which I was trying for last 2 hours.
@AbhishekKumar-rk5zm
@AbhishekKumar-rk5zm Жыл бұрын
Most appreciated about this Course is first how he tell the approach And then write alogirthm and then code which is a approach a engineer have to follow.
@KaranSingh-bm3wx
@KaranSingh-bm3wx 2 жыл бұрын
Bhaiya the explanations are too good. Just an FYI, floyd wale me loop detection me base case me head.next != null bhi check karna hoga as if we have a normal linkedList with just one node, uske lie bhi cycle bolega. kyuki apn if k andar jayenge fir dono slow aor fast ko next kar denge that is null and fir compare karne pe bolega ki loop hai bhaiya. I know its just that aap vscode me kara rhe the islie miss ho gaya. Meko gfg me error aya solve karne me fir mila :D
@garvitarora7777
@garvitarora7777 Жыл бұрын
yes bro you are absolutely right. thanks for telling the error
@yashsinghal237
@yashsinghal237 Жыл бұрын
hey, if you don't mind can you share the GFG code?
@naneradalsukh6839
@naneradalsukh6839 Жыл бұрын
+1
@sakshamsharma295
@sakshamsharma295 Жыл бұрын
this video series iam watching is cleraing my concepts of linked list it is a good coding channel i ever seen. Also great lectures which are helping in clearing my concepts .
@keshavarya7918
@keshavarya7918 2 жыл бұрын
Me to interviewers : Hello Jee! Kaise ho saare 😎 Interviewer : isko to Bangalore le jana padega
@parul8334
@parul8334 Жыл бұрын
you are really a great person who is helping us in such a nice way . Please keep it up.🥰🥰
@animeshpandey2911
@animeshpandey2911 Жыл бұрын
finally realized how to find starting point of the cycle ....thanks a lot
@avibirla9863
@avibirla9863 2 жыл бұрын
Maza aa gaya bhaiya .....mehnat safal hui aapka meri taraf se ..sab samj aa gaya abhi ...5 tarike dhundhne jaa raha hu ...Ly ♥️
@sudhanshudwivedi9610
@sudhanshudwivedi9610 2 жыл бұрын
Thank you Bhaiya, We are really motivated by the number of efforts you put 🙏
@satvikshukla596
@satvikshukla596 2 жыл бұрын
Thank you sir We are really motivated by the amount of efforts you put 🙏
@RohitRana-tz2lr
@RohitRana-tz2lr 2 жыл бұрын
Thanks, bhaiya for explaining this question in so much depth and detail...Hats off to you bhaiya
@kunalbhatia1311
@kunalbhatia1311 Жыл бұрын
maja azagaya bhaiya...watching it after 1 year of making and this playlist is golden
@ThePrajaktaVlogs
@ThePrajaktaVlogs 2 жыл бұрын
maja aa rha hai bhaiya, mene jab syllabus me pdha tha LL to bahot tough lga tha, but ab to baccho wali game lgta hai ; )
@amanpratapsingh7030
@amanpratapsingh7030 2 жыл бұрын
sir your videos are very helpful for me thankyou love bhaiya you had done a great job of providing free content which provide knowledge more than the paid course
@saurabhrajput7492
@saurabhrajput7492 2 жыл бұрын
Nice explaination....... int rating=0; while(explaination != Superb){ rating++; }
@sachitdhamija1884
@sachitdhamija1884 2 жыл бұрын
aaj ka kota pura ab kal dekho ga bye lage raho bhaiye effort!!! bhaiya puri mehnat dekh rhi h thank u so much
@MAYANKKUMAR-dh9eh
@MAYANKKUMAR-dh9eh Жыл бұрын
Thank you bhaiya for making this video in deep thank you apne is ko 15 min mei nhi smjhaya.. following this course from very first lecture 💌🍀❤
@prashantmaurya6868
@prashantmaurya6868 2 жыл бұрын
Thanks big b finally coding is looking sooooo easy because of you ....
@militaryink319
@militaryink319 2 жыл бұрын
thanks bhai for the series, i never followed a series like dis . love you bhai
@yashgupta4866
@yashgupta4866 2 жыл бұрын
Bhaiya course is going amazing 👍👍👍👍👍 Placement ki majboori mai shuru kra tha pr abb mja aane lga hai 😅😅😂😂
@tjstar390
@tjstar390 2 жыл бұрын
Thank bhaiya for giving such a beautifull and excellent contnet for us.
@meetved9122
@meetved9122 Жыл бұрын
1. map visited; is used to detect Loop in LL.
@meetved9122
@meetved9122 Жыл бұрын
Approach 2. Using Floyd cycle detection , we save time complexity compared to approach 1. Also, we are using slow and fast concept in this method. If fast==slow then Linked List is circular.
@sonarikadas3500
@sonarikadas3500 2 жыл бұрын
Thank you vaiya... you have explained all the concepts very well.... your course is zero to HERO wala hain....
@yashchampaneri1972
@yashchampaneri1972 2 жыл бұрын
28:50 piche lakshya be like : ye babber kab lecture complete karega and muje chair milegi!
@zaxaurav2276
@zaxaurav2276 2 жыл бұрын
Love u sir, m abhi consistent nahi ho paya pr aaj se fir continue karra hu, aap fir bhi consistent ho😔😇
@shubhammathur792
@shubhammathur792 11 ай бұрын
majaa aa gaya previously when bhaiya writes code i have to check again n again to write code but now i can understand code clearly when bhaiya write it and i am able to write code in one goo..
@Akarsh_2001
@Akarsh_2001 Жыл бұрын
Bhaiya Your way of explaining concepts are very amazing......
@rakhshanahmad8057
@rakhshanahmad8057 Жыл бұрын
Amazing explanation. Thanks love bhayya❤
@satyamjha-codeindwala6666
@satyamjha-codeindwala6666 Жыл бұрын
ou are really a great person who is helping us in such a nice way . Please keep it up.🥰🥰
@aryansen2410
@aryansen2410 3 ай бұрын
Amazing Lec. babbar bhaiya maza aa gaya
@AbhimanyuPA
@AbhimanyuPA Жыл бұрын
bhaiya thank you from bottom of my heart you put real effort for us(along with us) of course!! 😄
@wesle_y__
@wesle_y__ Жыл бұрын
love you bhaiya , hame bhot help mil rahi hai in videos se !!
@user-iq3xc5hn9h
@user-iq3xc5hn9h 5 ай бұрын
Thank you for such a detailed explanation.
@anuragtiwari4182
@anuragtiwari4182 2 жыл бұрын
easy to understand..because you teach so well....kudos to you bhaiya🙏🙇🙇
@VinayKumar-ze7bh
@VinayKumar-ze7bh 6 күн бұрын
bhai yee wala video best tha poora ka poora samaj mai agaya
@himanshurathore9005
@himanshurathore9005 2 жыл бұрын
bhaiya, I really appreciate your efforts . god bless you. ❤️
@anuragpandey8165
@anuragpandey8165 2 жыл бұрын
14:24 I think TC will be O(nlogn), log(n) extra because of insertion in map. It would be O(n) if we would have used an unordered_map instead.
@sounaksaha1455
@sounaksaha1455 2 жыл бұрын
+1
@aditya_0524
@aditya_0524 2 жыл бұрын
Bro please check if this code runs in your compiler or not, because the loop is present statement is not running in my compiler. #include #include #include using namespace std; class Node{ public: int data; Node * next; Node(int data){ this->data = data; this->next = NULL; } }; void insertAtHead(Node* &head, int d){ //creating new node which then will be our first node-> Node* node2 = new Node(d); node2->next = head; head = node2; } void insertAtTail(Node* &tail, int d){ //creating new node which then will be our first node-> Node* node2 = new Node(d); tail->next = node2; tail = node2; } void insertAtPosition(Node* & tail, Node* & head, int position, int d){ //Using below condition we are inserting the given element at start, // and then updating the head-> if(position == 1){ insertAtHead(head, d); return; } Node* temp = head; int count = 1; while(count < position-1){ temp = temp->next; count++; } //if we are inserting at the end, then this condition will update the tail-> if(temp->next == NULL){ insertAtTail(tail, d); return; } //Creating a node for d-> Node* nodeToInsert = new Node(d); nodeToInsert->next = temp->next; temp->next = nodeToInsert; } void print(Node* & head){ Node* temp = head; while(temp != NULL){ cout
@yasharodiya2085
@yasharodiya2085 2 жыл бұрын
hmm you're right, but we can remove this logn complexity by using an unordered_map instead of a normal one... It's implementation is different than the normal one. So the operations take constant time.. There's a video about it, do watch it... kzfaq.info/get/bejne/nbuimbuLlc7Vn3U.html
@naneradalsukh6839
@naneradalsukh6839 Жыл бұрын
+1
@user-xo8qx5bn4f
@user-xo8qx5bn4f Жыл бұрын
yar babbar bhai yea na pocha kro k video kesi lgi.......level hi ho gya really mtlb best best best
@ShivamTiwari-ht8cz
@ShivamTiwari-ht8cz 2 жыл бұрын
thks bhaiya for a best DSA series for student
@prashantbirajdar9271
@prashantbirajdar9271 2 жыл бұрын
wah bhaiyaa mza a gya smj aya sub ekdum badiya tarike se❤💯👍👍
@AbdulBasit_1211
@AbdulBasit_1211 Жыл бұрын
yaar kya lecture tha mza agaya bhai
@riyadhossain1706
@riyadhossain1706 Жыл бұрын
I really appreciate your efforts and dedication to making such awesome content for us. Much obliged to you.
@sanjnasahu1799
@sanjnasahu1799 10 ай бұрын
You are the best teacher 🔥🔥 This lecture is very awesome 👍
@suranjandhara7535
@suranjandhara7535 2 жыл бұрын
Aa gya hu bhaiya.... Iske baad haar roj hi video ayega lag raha hai.....❤️❤️❤️❤️❤️❤️❤️ Thanks bhaiya.... For such amazing 😍😍 content ....
@adanulabidin
@adanulabidin 8 ай бұрын
Some serious work was done. Thank you bhai.
@muneebjaved3940
@muneebjaved3940 Жыл бұрын
Bohat mehnat kartay hen ap bhayia salute ha 🔥🔥🔥
@kakshat22
@kakshat22 Жыл бұрын
Bhaiya really Nice and amazing explanation , Concept became crystal clear.....
@makelearningeasy111
@makelearningeasy111 Жыл бұрын
Bahot badhiya kaam kr rhe.🥰
@samsmith3961
@samsmith3961 Жыл бұрын
very well explained;; finally got this topic
@amritbhardwaj8295
@amritbhardwaj8295 2 жыл бұрын
Thank You Sir for the Wonderful course..........
@samaysarah7417
@samaysarah7417 2 жыл бұрын
Thank you sir iss course ke liye.... Sir greedy kab se start kroge??
@priyanshusrivastava2145
@priyanshusrivastava2145 Жыл бұрын
one of the best content on linked list
@sounaksaha1455
@sounaksaha1455 2 жыл бұрын
Attendance marked bhaiya ji both for OS & DSA..... hum saab champ banenge ..... barabar banenge...... Lots of lOve
@iitianashishmadhukar9861
@iitianashishmadhukar9861 Жыл бұрын
this course is more than inouf and love babbar bhaiya put the maximum in this course and far better than paid course❤❤❤❤❤💖💖
@ombhurke5688
@ombhurke5688 10 ай бұрын
Best explanation of such a deep concept fr🐐
@mr.himanshu4299
@mr.himanshu4299 2 жыл бұрын
keep uploading thanks for the course babbar bhai
@vivekparashar...8716
@vivekparashar...8716 2 жыл бұрын
Bro this video is great for learning deep concept in ll
@roshanansy6901
@roshanansy6901 Жыл бұрын
high level understanding bhiya thanks for it .
@udaypratapsingh8923
@udaypratapsingh8923 2 жыл бұрын
subha se baar baar you tube khol ke dekh raha th akab aayegi video ....... or ab aa gyi
@abhishekmasali5351
@abhishekmasali5351 2 жыл бұрын
Bhaiya video toh ek badiya hai Thank You so much
@computerguy3550
@computerguy3550 Жыл бұрын
Gajab Ki Video hai bhaiya Maza Ahhyga👌👌👌👌
@BhaiRayyanKiDuniya
@BhaiRayyanKiDuniya 2 жыл бұрын
good job bhaiya. you really deserve a loooaaddd of thanks!!
@SriniVas-mx1li
@SriniVas-mx1li 2 жыл бұрын
Thanks is a very small word to tell you Love bhai ♥️ We won't let u down Love bro. Shayad seekhna delay hoga, par seekenge saare pakkaaa 🌀 *Srinivas from AP, reporting bhai!* 🚀
@thinker-o5p
@thinker-o5p 2 жыл бұрын
zabardast video tha bhaiya concepts ekdam clear hai😁
@swatinageshwar4667
@swatinageshwar4667 2 жыл бұрын
Thank you .....superbb!! explanation
@Edit2308
@Edit2308 10 ай бұрын
at 35:55 slow is increasing by 1 and also intersection increasing by 1 so this is a infinite loop condition . here both are increased by 1.
@anuradha3868
@anuradha3868 9 ай бұрын
Crrct even I got that after dry run on different example
@srajittanwar636
@srajittanwar636 2 жыл бұрын
Present Josh high bhaiya mujhe bohat daar lagta h placements ka khudse logic nhi soch pata hu but aap jo bhi padhate ho sab smj ata h ,pta nhi ky hoga mera 6 mahine me placements h
@op-zm8sw
@op-zm8sw 10 ай бұрын
Bro placement hua??
@sushilsingh9632
@sushilsingh9632 2 жыл бұрын
Thanks bhaiya for such amazing content🤗.
@Abc-lr4bf
@Abc-lr4bf Жыл бұрын
thanks a lot bhayia
@tusharmukherjeeju-cse5773
@tusharmukherjeeju-cse5773 Жыл бұрын
Thank you bhaiyaa 💖💖
@sandeepkumarg1889
@sandeepkumarg1889 10 ай бұрын
maza aa gya bhaiya,everything crystal clr
@princepal8523
@princepal8523 Жыл бұрын
amazing explanation bhaiya 🔥🔥
@arpit7618
@arpit7618 Жыл бұрын
Thankuhh soo much Bhaiya
@ajujat4032
@ajujat4032 11 ай бұрын
thank you so much sir ji your teching style are amazing🥰🥰
@vivekjain5102
@vivekjain5102 Жыл бұрын
thank you so much for such quality content
@shubham76
@shubham76 Жыл бұрын
Very good explanation 😄😄 bhaiya Aaj to swad hi aa gya linked list ki 😋😋 Love you babbar bhaiya
@kundantarafdar3663
@kundantarafdar3663 2 жыл бұрын
MAJAA AA GAYAA BHAIYAA...EXCELLENT EXPLAINATION👌👌
@RohitSingh-hc8yi
@RohitSingh-hc8yi Жыл бұрын
thankyou for such a quality content
@ShariqueAkhtar
@ShariqueAkhtar Жыл бұрын
thankyou bhaiyya
@Zainn686
@Zainn686 Жыл бұрын
Thank you Bhaiya ❤
@nitinkush9316
@nitinkush9316 Жыл бұрын
Gajab video hai guru ji 🙏🙏🙏
@sandeepsirfanpage6281
@sandeepsirfanpage6281 Жыл бұрын
understood the topic completely sir... maza a haga
@manishvijay6794
@manishvijay6794 2 жыл бұрын
dekh rhe h bhaiya puri videoes don't worry about that full on josh ke sath tier-3 vale har nhi manenge
@AA-wy9vw
@AA-wy9vw 2 жыл бұрын
Present bhaiya. Loving the series.
@nikitasinha8181
@nikitasinha8181 Жыл бұрын
Thank you so much 🙏
@top_10_2.O
@top_10_2.O Жыл бұрын
thankss bro
@shivkumar-og4ow
@shivkumar-og4ow 2 жыл бұрын
thank you bhaiya ! you are doing good job
@NEXTTRYGAMING
@NEXTTRYGAMING 2 жыл бұрын
op video seiously 🔥ise kehte hai genuine content
Lecture 48: Remove Duplicates from a Sorted/UnSorted Linked List
27:25
CodeHelp - by Babbar
Рет қаралды 180 М.
Slow motion boy #shorts by Tsuriki Show
00:14
Tsuriki Show
Рет қаралды 10 МЛН
لااا! هذه البرتقالة مزعجة جدًا #قصير
00:15
One More Arabic
Рет қаралды 15 МЛН
小宇宙竟然尿裤子!#小丑#家庭#搞笑
00:26
家庭搞笑日记
Рет қаралды 16 МЛН
Why UK 🇬🇧 is going Bankrupt? : Detailed Economic Case Study
20:37
What's going on with Windows Laptops?
10:30
Marques Brownlee
Рет қаралды 2,7 МЛН
Watch This To Become Crorepati FAST, Real Estate Secrets of Ultra-Rich
22:07
Finance With Sharan
Рет қаралды 118 М.
Lecture 49: Merge 2 Sorted Linked Lists || Sort 0s, 1s and 2s in Linked List
58:44
L14. Detect a loop or cycle in LinkedList | With proof and Intuition
20:26
The PERFECT Desi Girl 😍 | Omegle long conversations & more ❤️
21:43