Detection and Removal of Cycle in Linked List | Lecture 22.5

  Рет қаралды 165,385

Apna College

Apna College

3 жыл бұрын

Complete C++ Placement Course (Data Structures+Algorithm) : • C++ Full Course | C++...
Telegram: t.me/apnikakshaofficial
Instagram: / dhattarwalaman
Notes of this Lecture:

Пікірлер: 356
@deepanshumahto8086
@deepanshumahto8086 3 жыл бұрын
i think your removeCycle() function will not remove the cycle if the cycle starts at head node itself. So here is the corrected one void removeCycle(node* head){ node* hare=head ; node* tortoise=head ; do{ hare=hare->next->next ; tortoise=tortoise->next ; }while(hare!=tortoise) ; if(hare==head){ while(tortoise->next!=head) tortoise=tortoise->next ; tortoise->next=NULL ; return ; } hare=head ; while(hare->next!=tortoise->next){ hare=hare->next ; tortoise=tortoise->next ; } tortoise->next=NULL ; }
@Rohan-ov3fr
@Rohan-ov3fr 3 жыл бұрын
Ys bro its absolutely correct because I m also facing same issue but now I got it 👍
@aryanttripathi
@aryanttripathi 3 жыл бұрын
@@anubhabray5254 class Solution { public: //Function to remove a loop in the linked list. bool detectCycle(Node* head) { Node* fast = head; Node* slow = head; while(fast != NULL && fast -> next != NULL) { slow = slow -> next; fast = fast -> next -> next; if(slow == fast) { return true; } } return false; } void removeLoop(Node* head) { // code here // just remove the loop without losing any nodes if(detectCycle(head) == false) { return; } Node* fast = head; Node* slow = head; do { slow = slow -> next; fast = fast -> next -> next; }while(fast != slow); if(fast == head) { while(slow -> next != head) { slow = slow -> next; } slow -> next = NULL; return; } fast = head; while(slow -> next != fast -> next) { slow = slow -> next; fast = fast -> next; } slow -> next = NULL; } };
@rohandeshmukh3989
@rohandeshmukh3989 3 жыл бұрын
@@anubhabray5254 yeah bcz if you dry run it , it will go inside an infinite loop if suppose you have 5 node from 1 to 5 and your cycle is also from head means(1) to the last node (5) then there cycle detection point comes out to be 2 and after that for removing cycle you are rearranging the fast pointer to the head and slow at same point means at 2 only so if both pointers are traversing by only one node then their next will not meet anywhere so it runs to an infinite loop they did not cover the case if cycle detected at head node to last node
@rishavkumar6383
@rishavkumar6383 2 жыл бұрын
@@Rohan-ov3fr can pls upload the code here
@SaifAli-nt5sh
@SaifAli-nt5sh 2 жыл бұрын
@@anubhabray5254 probably you don't have all pointer checks in your conditional statement
@KrishnaGupta-xd6xu
@KrishnaGupta-xd6xu 3 жыл бұрын
Aman bhaiya please make sure ki yeh course pura complete ho and Very thankful for your efforts for us ❤
@sauravchaudhary3064
@sauravchaudhary3064 3 жыл бұрын
I am loving this course, thanks for your efforts. Can't express my feelings in my words. Thank you so much
@talhamumtaz2678
@talhamumtaz2678 2 жыл бұрын
Thanks aloooot didi, your way of teaching is mind blowing. Feeling blessed for being a student of APNA COLLEGE!
@harshitsaxena7205
@harshitsaxena7205 Жыл бұрын
I am adding this comment for upcoming students who will watch this video that the content in this video from starting to end is extremely helpful in building core concepts (specially proving in last few minutes) of various real world problem and particularly to linked list so after watching this kindly practice leetcode questions to make grip over this concept and try not to extend your practice session while learning to future. HAPPY CODING🙂
@darshantrivedi5390
@darshantrivedi5390 3 жыл бұрын
Web development ka video plz🙏🙏🙏
@foreducation408
@foreducation408 2 жыл бұрын
this is such a good video spatially the part where she explained how to break the cycle.
@harshgupta2699
@harshgupta2699 2 жыл бұрын
This is the best explanation of "detection and removal of cycle in linked list" i have come across. Thank you!
@ankitkumar-mi2of
@ankitkumar-mi2of 2 жыл бұрын
In which year u r ?
@anushkakumari535
@anushkakumari535 5 ай бұрын
I am in first year second sem
@codehustler8582
@codehustler8582 3 жыл бұрын
Great work sir plz continue 💯
@mohammadahsan7873
@mohammadahsan7873 3 жыл бұрын
Very Well Explained. Thanks 👌❤️
@Chaitanya_6444
@Chaitanya_6444 3 жыл бұрын
👍Thanks for the awesome playlist....
@yogeshsanap8453
@yogeshsanap8453 3 жыл бұрын
Great explanation ! Thank You
@mhamza016
@mhamza016 3 жыл бұрын
Please upload web development next class
@harshpanwar1550
@harshpanwar1550 2 жыл бұрын
Hats off to u didi...... Explained in such a nice manner😄😄
@subratsahai2017
@subratsahai2017 3 жыл бұрын
thanks bhiya and everyone associated with the project , the playlist has been a great help
@YashSharma-qo1sy
@YashSharma-qo1sy 3 жыл бұрын
Lectures are really world class,loved it.🙏🙏🙏🙏🙏🙏👍👍👍👍👍. PLS CONTINUE WEB DEVELOPMENT VIDEOS ALSO.
@Animesh045
@Animesh045 3 жыл бұрын
kzfaq.info/get/bejne/a7CalKpzyb-WeqM.html fdba
@nikheelindanoor3073
@nikheelindanoor3073 3 жыл бұрын
The code won't work if the loop starts at the first node itself
@satyamjaiswal5981
@satyamjaiswal5981 3 жыл бұрын
yeah you are right the code is not working for this corner case and when try to submit it on geekforgeeks it gives error at this case
@majidmohd100
@majidmohd100 3 жыл бұрын
Is this course going very slow? Not according to the timeline given ya?
@x_x3557
@x_x3557 3 жыл бұрын
The above approach doesn't work when the loop is from the last node to the first node.
@jayprakashsaini611
@jayprakashsaini611 3 жыл бұрын
it works dear.
@tarunbisht8016
@tarunbisht8016 3 жыл бұрын
@@jayprakashsaini611 no the remove cycle doesnt work, tey urself u will lose all nodes except head after removing the cycle
@tarunbisht8016
@tarunbisht8016 3 жыл бұрын
@@jayprakashsaini611 lit bit code u can add if(slow==fast)//when my circle is from first to the last node for that aka circular linked list. { while(fast->next!=slow) { fast=fast->next; } fast->next=NULL; return ; }
@kushagra4401
@kushagra4401 3 жыл бұрын
@@anuragpandey3341 hey, this code worked ,share your code i will tell you why u got error void removeLoop(Node* head) { Node *fast=head,*slow=head,*sp; while(fast!=NULL && fast->next!=NULL){ sp = slow; slow = slow->next; fast = fast->next->next; if(fast==slow) goto l1; } return; l1: if(slow==head){ sp->next = NULL; return; } fast = head; while(fast->next!=slow->next){ fast = fast->next; slow = slow->next; } slow->next=NULL; }
@anuragpandey3341
@anuragpandey3341 3 жыл бұрын
@@kushagra4401 My code was: void removeLoop(Node* head) { // code here // just remove the loop without losing any nodes Node* fast = head; Node* slow = head; while(fast->next != NULL && fast != NULL) { fast = fast->next->next; slow = slow->next; if(fast == slow) { break; } } if(fast->next == NULL || fast == NULL) return; fast = head; if(fast == slow) { while(slow->next != fast) { slow = slow->next; } Node* todelete = slow->next; slow->next=NULL; delete todelete; return; } else { while(fast->next != slow->next) { fast = fast->next; slow = slow->next; } Node* todelete = slow->next; slow->next = NULL; delete todelete; return; } }
@shaantyagi2187
@shaantyagi2187 3 жыл бұрын
ha ha it is going into my head with very smooth way !
@yashverma7084
@yashverma7084 3 жыл бұрын
hats off to you guys explanation
@ashishsundriya621
@ashishsundriya621 3 жыл бұрын
RemoveLoop from linked list won't work when 1->2->3->4->1 i.e loop is present at the first element of the Linked list only. In this case, after loop detection both slow and fast pointers point to the head.
@blizzardstorm9715
@blizzardstorm9715 3 жыл бұрын
yes
@pendyalaabhishek8866
@pendyalaabhishek8866 2 жыл бұрын
you should check for that case . keep a prev pointer to slow and when slow == fast at head prev->next ==NULL;
@hrithikjaysingpure9623
@hrithikjaysingpure9623 2 жыл бұрын
@@pendyalaabhishek8866 It seems correct to me and working fine in IDE but idk why GFG isn't accepting this solution either it's throwing a nullpointer exception.
@souravsarkar6107
@souravsarkar6107 3 жыл бұрын
Great Explanation Mam!!
@agamsingh8664
@agamsingh8664 3 жыл бұрын
Sir has forgotten Apni Kaksha Password I think so😂😂😛😛
@rahulsheikh9801
@rahulsheikh9801 6 ай бұрын
What an explanation it was ,,,,,,thanks a lot
@ramankr0022
@ramankr0022 11 ай бұрын
very helpful. thanks for uploading.
@gamingblast2325
@gamingblast2325 3 жыл бұрын
IN this condition 7->38->36->34->16 if we make loop cycle at 1 i.e 16->7 making a loop then removeloop function will now work as both slow and fast ptr will end up on head and then slow->next = NULL is remove link s 7 38->36->34->16->7 as link between head and head->next is removed with above function algorithm
@pranavmishra5211
@pranavmishra5211 3 жыл бұрын
apna college teachers are really good ngl
@utkarshawasthi3368
@utkarshawasthi3368 3 жыл бұрын
Felling first with 39 others 😂😂😂
@Kidzone1289
@Kidzone1289 3 жыл бұрын
Kya aap funny videos or memes psand hai toh ye dekho kzfaq.info/get/bejne/bcqIdNuo25itkn0.html
@MusicLover-sd2hp
@MusicLover-sd2hp 3 жыл бұрын
*69 😎🤣
@harshitrathi3077
@harshitrathi3077 3 жыл бұрын
@Animesh 045 Disliking Your Video
@harshitrathi3077
@harshitrathi3077 3 жыл бұрын
@@Animesh045 Yaa and Even Thanks to My Group where i have share your video link to dislike
@Animesh045
@Animesh045 3 жыл бұрын
@@harshitrathi3077 thank you soo much beacuse vo sab aake video dekhenge even views badhyenge
@IronMan-fe8uf
@IronMan-fe8uf 3 жыл бұрын
Welcome to apna comment section 😂😂😂
@prashantchakrawarti42
@prashantchakrawarti42 3 жыл бұрын
Thanku soo much 🙏🙏🙏 Finally DIDI JI🙏
@Animesh045
@Animesh045 3 жыл бұрын
kzfaq.info/get/bejne/hLqUnJaXmMCyaKM.html great t t !!
@rahul_ji21
@rahul_ji21 3 жыл бұрын
Add this below fast=head; in removeCycle function for exceptional case of if the cycle starts at the first node only if(fast -slow) { while(slow->next !=fast) { slow-slow->next; } slow->next=NULL; return; }
@Big_Man_Dhariwal
@Big_Man_Dhariwal 3 жыл бұрын
#amandhattarwal #apnacollege Slow ho gye bhaiya course me 😐 Lamba break le liya aapne 😓
@jals413
@jals413 3 жыл бұрын
kzfaq.info/get/bejne/p5t-d9WYutPbf2Q.html Mast Edit kiya hai dekh lena ek baar Also leave a like and Subscribe
@rambabupatidar3092
@rambabupatidar3092 3 жыл бұрын
For creating loop do put this in main() head->next->next->next->next = head ;
@rushikeshubale9301
@rushikeshubale9301 2 жыл бұрын
Great explaination didi...!!
@vinayakd4444
@vinayakd4444 3 жыл бұрын
Enable ads bhai. You are giving us so much of value. Please enable ads and also sponsorships. Thanks a lot!!
@prakharagarwal6237
@prakharagarwal6237 3 жыл бұрын
To bhau donate kardo
@Sanidhya_Goyal
@Sanidhya_Goyal 3 жыл бұрын
Mann that proof deserves a Like!!!
@PepeTheFrog2016.
@PepeTheFrog2016. 3 жыл бұрын
Everyone is first untill they refresh
@shivammaurya3451
@shivammaurya3451 3 жыл бұрын
Thank u mam best explanation
@TrueSolutionsOfficial
@TrueSolutionsOfficial Жыл бұрын
this is very good explanation
@ShubhamKumar-gz5rr
@ShubhamKumar-gz5rr 2 жыл бұрын
thank you for this video
@viraltoovideos
@viraltoovideos Жыл бұрын
Nice explain mam thank you❤️❤️❤️❤️
@patalamrithish6838
@patalamrithish6838 2 жыл бұрын
Best Videp on DSA
@aashishjoshishorts
@aashishjoshishorts 3 жыл бұрын
Web development javascript kab aayega
@idrisbohra5176
@idrisbohra5176 3 жыл бұрын
Please upload the rest videos fast, we can't wait to complete the course . It is so good😜
@Animesh045
@Animesh045 3 жыл бұрын
kzfaq.info/get/bejne/hLqUnJaXmMCyaKM.html rtesh
@AnkitKumar-vd2dd
@AnkitKumar-vd2dd 3 жыл бұрын
When will this course complete?
@PrakashKumar-vr9wc
@PrakashKumar-vr9wc 3 жыл бұрын
It's help lot's of me
@vidyutphagetra3804
@vidyutphagetra3804 3 жыл бұрын
great explaination
@amoghmishra8745
@amoghmishra8745 2 жыл бұрын
The remove cycle function is wrong it may not work in several conditions, I think the correct function should be: void remove_cycle(node *&head) { node *slow = head; node *fast = head; do { slow = slow->next; fast = fast->next->next; } while (slow != fast); fast = head; while (slow->next != head) { slow = slow->next; } slow->next = NULL; return; }
@asishpanda3547
@asishpanda3547 2 жыл бұрын
very well explained
@soumikmukherjee4797
@soumikmukherjee4797 3 жыл бұрын
can someone tell me why are we using do while loop in the remove function instead of the while loop?
@anushkakumari535
@anushkakumari535 5 ай бұрын
Mam but aapne jo do while wale mein pehle hi tortoise ko ek aage badha diya aur uske baad rabit ko head pe bheja to aishe mein to 1 ka difference reh jaega na pos pe pahunchne se pehle to undone ka next kaise pos pe tend karega
@NomadStriver
@NomadStriver 3 жыл бұрын
excellent......
@codewithree930
@codewithree930 3 жыл бұрын
got it! :)
@UECAshutoshKumar
@UECAshutoshKumar Жыл бұрын
Thank you
@bhawnaaswani4777
@bhawnaaswani4777 3 жыл бұрын
it is very useful
@rutvikrana512
@rutvikrana512 3 жыл бұрын
Very nice explanation 💕
@jals413
@jals413 3 жыл бұрын
kzfaq.info/get/bejne/p5t-d9WYutPbf2Q.html Mast Edit kiya hai dekh lena ek baar Also leave a like and Subscribe
@starchamp4680
@starchamp4680 3 жыл бұрын
8.2 searching in array 21.3 inheritance 21.4 polymorphism These lectures notes are not available please upload these notes if its available. if i am wrong and notes of above available plz tell me below.
@ideaindia4278
@ideaindia4278 3 жыл бұрын
Sir please make a video on technical interview round how to crack it ?
@ssb6042
@ssb6042 Жыл бұрын
one of the rare codes where i have seen use of do while😅
@saicharan4669
@saicharan4669 2 жыл бұрын
But this code can not remove loop when the loop forms at first node i.e., the last node points back to the first node
@BRIJESHSAH_K_CO_
@BRIJESHSAH_K_CO_ 2 жыл бұрын
is this will work in case of circular ll ?
@arvindsingh.1387
@arvindsingh.1387 3 жыл бұрын
How is the quality level of it...plz tell?
@pushparajbhutekar2677
@pushparajbhutekar2677 3 жыл бұрын
Web development ka Lao yaar 😤 please bhaiya web development ka lao
@himanshu_________
@himanshu_________ 3 жыл бұрын
Yes brother mai v usi ka wait kr rha hun..
@jassmanakfan555
@jassmanakfan555 3 жыл бұрын
Phle isee hi ho Jane de
@jals413
@jals413 3 жыл бұрын
kzfaq.info/get/bejne/p5t-d9WYutPbf2Q.html Mast Edit kiya hai dekh lena ek baar Also leave a like and Subscribe
@harshitrathi3077
@harshitrathi3077 3 жыл бұрын
@Animesh 045 Bro Tuh Jitna Yeh Link Dalega utna Dislike Milegah Isliyee Thoda Kaam Dal
@Animesh045
@Animesh045 3 жыл бұрын
@@harshitrathi3077 ok bro kitna dislike karloge
@tanmaysatsangi131
@tanmaysatsangi131 3 жыл бұрын
Given code is wrong for the input: 7 58 36 34 16, and after 16 loop goes to the 1st element of the linked list i.e. 7. Please correct if I am wrong?????
@abhinavsingh9720
@abhinavsingh9720 2 жыл бұрын
Thanks
@arjavkanadia9730
@arjavkanadia9730 3 жыл бұрын
Even nodes(total) mei 2 nodes ke loop ke liye kaam nai karega (FYI)
@shubhamkale735
@shubhamkale735 3 жыл бұрын
when you realize you didnt do anything in your college times , linked list at another level Thank you
@pateldirgh3121
@pateldirgh3121 3 жыл бұрын
Sir when will web development class will be uploaded
@athleteprogrammer0073
@athleteprogrammer0073 3 жыл бұрын
Web dev ki playlist chalu kardo bhaiyaa please.. agar aap busy ho to inform kardo ki is time tak nahi aayegi ..tab tak ham self study kare.. Aap bahut acha kaam karta hai aman bhai!!!!
@Animesh045
@Animesh045 3 жыл бұрын
kzfaq.info/get/bejne/a7CalKpzyb-WeqM.html rHRBH
@abhyudaypratapsingh4325
@abhyudaypratapsingh4325 3 жыл бұрын
Love you mam ❤️❤️❤️
@AltafHussain-on2oe
@AltafHussain-on2oe 3 жыл бұрын
This code is not working for the testCase if cycle is forming at pos=1;
@manrajsandhu
@manrajsandhu 3 жыл бұрын
Waiting for Web Development Course
@rahulbajetha4057
@rahulbajetha4057 3 жыл бұрын
is this code work for circular linklist???
@ishanidey9580
@ishanidey9580 3 жыл бұрын
please kindly upload the notes and full codes also. i assume there are more like me who need them.
@InderjitSingh-sh9ve
@InderjitSingh-sh9ve 2 жыл бұрын
Khud bbnaalo
@prathamkumar3731
@prathamkumar3731 3 жыл бұрын
Aman bhaiya to coaching institute :biddu mera bacha hai tu 😂😂
@prathamkumar3731
@prathamkumar3731 3 жыл бұрын
@Animesh 045 krdiya subscribe
@thedreamballer
@thedreamballer 3 жыл бұрын
Android course with Notes, please bhaiya
@ppriya1297
@ppriya1297 3 жыл бұрын
Bhai jo hai usko pehle padh lo yaar. Uske baad request karna Android development ka course.
@thedreamballer
@thedreamballer 3 жыл бұрын
Mera kaam Android ka hai
@ppriya1297
@ppriya1297 3 жыл бұрын
@@thedreamballer Ek khatam hone ke baad dusra aayega. Wo log koi robots nahi hai jo ek ke baad ek course leke aayenge ek hi time pe. Still they're providing the best of the opportunities.
@thedreamballer
@thedreamballer 3 жыл бұрын
I am not disrespecting anyone not even Aman Bhaiya but still I will write my suggestions in the comments
@udaypratapsingh8923
@udaypratapsingh8923 2 жыл бұрын
awesome
@pawananubhav12
@pawananubhav12 3 жыл бұрын
thank you !!
@Animesh045
@Animesh045 3 жыл бұрын
kzfaq.info/get/bejne/a7CalKpzyb-WeqM.html FSb
@no_one3184
@no_one3184 3 жыл бұрын
Plz upload a new vedio this code of removing loop is not working when loop is connected to first node🙏🙏
@rahulgoel5558
@rahulgoel5558 2 жыл бұрын
if cycle is at head node then this condition also goes:- if (slow == head && fast == head) { while (slow->next != fast) slow = slow->next; slow->next = NULL; return; } whole code will be:- class Solution { public: //Function to remove a loop in the linked list. void removeLoop(Node* head) { // code here // just remove the loop without losing any nodes if (head == NULL) return; Node* fast = head; Node* slow = head; while (fast != NULL && fast->next != NULL) { fast = fast->next->next; slow = slow->next; if (slow == fast) break; } if (slow == head && fast == head) { while (slow->next != fast) slow = slow->next; slow->next = NULL; return; } if (slow == fast) { slow = head; while (slow->next != fast->next) { slow = slow->next; fast = fast->next; } fast->next = NULL; } } };
@prathamrana8433
@prathamrana8433 3 жыл бұрын
Dii Apne cycle walala linklist bnana you sikhaya hi nhi apne toh detect and remove kaise krte h vo btaya Make Cycle wala function Bhi bta do
@dharmeshpoladiya9047
@dharmeshpoladiya9047 3 жыл бұрын
The cycle removal gives wrong answer for a exception if the last element of link list is pointing to the first element of linkedlist. In that case both our slow and fast pointer will point to the head and then we will remove the slow->next=Null which will remove the link between the first and second element but we have to remove link between last and first element of linkedlist eg: 1->2->3->4->5->1 My Solution in Python def removeLoop(self, head): if(head==None or head.next==None): return low = head high = head while(low!=None and high!=None and high.next!=None): high = high.next.next low = low.next if(high==low): break if(low==head): while(high.next!=low): high = high.next high.next = None elif(low==high): low=head while(low.next != high.next): low = low.next high = high.next high.next = None
@SaifAli-nt5sh
@SaifAli-nt5sh 2 жыл бұрын
Corner case of all elements being in the cycle won't work here! (Meeting point of slow and fast is head) Infinite loop! Crazy bug for tutorial standards
@khanresearchcenterunoffici311
@khanresearchcenterunoffici311 3 жыл бұрын
❣️🔥
@yashaswinisharma4185
@yashaswinisharma4185 3 жыл бұрын
heyyy I guess the code to remove the cycle skipped a case when the slow will point to head, i.e., that it form a circular linked list sorts of
@Priyasingh-xr6df
@Priyasingh-xr6df 3 жыл бұрын
yeah!
@74N
@74N 2 жыл бұрын
Exactly
@itsaryanguys
@itsaryanguys 3 жыл бұрын
❤️🙏
@soni.himansh
@soni.himansh 3 жыл бұрын
remove cycle function is not working for if the cycle is at a head node?
@dakshagarwal1463
@dakshagarwal1463 3 жыл бұрын
ya man
@hanumansidh2287
@hanumansidh2287 3 жыл бұрын
Removing is not working when there is 5 element and loop starting from 1St element
@manmeetsinghchhabra3923
@manmeetsinghchhabra3923 3 жыл бұрын
Can someone tell how can I correct it too pass all cases ? Node* slow; Node* fast; slow=fast=head; do { slow=slow->next; fast=fast->next->next; }while(slow!=fast); if(fast == head) { while(slow -> next != head) { slow = slow -> next; } slow -> next = NULL; return; } head=fast; while(slow->next!=fast->next) { slow=slow->next; fast=fast->next; } slow->next=NULL; }
@amolsingh9538
@amolsingh9538 3 жыл бұрын
In detect cycle wale code mai you missed one very important cast that is what if there is a full loop.Please see to it.
@sahilahmed5596
@sahilahmed5596 3 жыл бұрын
wahi bhai test case pass nhi ho rha isse
@utkarshnigam1573
@utkarshnigam1573 3 жыл бұрын
the code is not working for all test cases .Please help.
@adarshmishra8198
@adarshmishra8198 3 жыл бұрын
Removing isn't working when there are 5elements in list and loop is at first element.. Please help me..I got this as wrong test case in gfg
@afsanVlog1100
@afsanVlog1100 3 жыл бұрын
you are right @adarsh mishra ,I also tried
@008abhishekvishwakarma9
@008abhishekvishwakarma9 3 жыл бұрын
I also stuck in the same situation...help me please
@adarshmishra8198
@adarshmishra8198 3 жыл бұрын
@@008abhishekvishwakarma9 bro you can add an extra condition regarding this situation or you can solve this problem using map to..
@zaveriamutwalli6399
@zaveriamutwalli6399 3 жыл бұрын
Why node* &head and not node* head in detect cycle function
@jitengarg5740
@jitengarg5740 3 жыл бұрын
remove this condition that if is fast==slow return true instead return slow->data U will able to Finding middle element in a linked list easily and it will pass all the test-cases. :)
@jiosim1377
@jiosim1377 3 жыл бұрын
This is not to find middle element.its just to detect if a cycle is present
@sumitsingh-gn4ed
@sumitsingh-gn4ed Жыл бұрын
may be remove cycle will not work if both slow and fast pointer will meet at loop node.
@MOHANKALYANI-lf9xt
@MOHANKALYANI-lf9xt Жыл бұрын
why did they use the do while loop , @apnacollege please explain
@kunaltaneja8551
@kunaltaneja8551 Жыл бұрын
There is one more thing that while allocating memory to our nodes dynamically, we are not deallocating memory of nodes after use so it will cause to memory leakage at every exution of same code
@sharansai792
@sharansai792 3 жыл бұрын
You guys did not mention the exception case.
@AnkitKumar-vd2dd
@AnkitKumar-vd2dd 3 жыл бұрын
When will this course complete?
@Animesh045
@Animesh045 3 жыл бұрын
kzfaq.info/get/bejne/a7CalKpzyb-WeqM.html FDHBFR
@mriganksrivastava3821
@mriganksrivastava3821 Жыл бұрын
Don't you think that adding the fast->next!=NULL is enough, and we don't neeed to add the fast!=NULL condition in while loop, while detecting a cycle
@deepanshukumar7290
@deepanshukumar7290 3 жыл бұрын
agar cycle head pe hu toh fast slow head pe he aa jaege ?????????????
L14. Detect a loop or cycle in LinkedList | With proof and Intuition
20:26
Inside Out Babies (Inside Out Animation)
00:21
FASH
Рет қаралды 23 МЛН
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 43 МЛН
哈莉奎因以为小丑不爱她了#joker #cosplay #Harriet Quinn
00:22
佐助与鸣人
Рет қаралды 8 МЛН
Why so many Coding Languages are created?
10:01
Apna College
Рет қаралды 598 М.
What's wrong with Engineering Degree ? What can we do as a student?
14:25
What is Docker? Simply Explained by Shradha Ma'am
19:32
Apna College
Рет қаралды 266 М.