Complete C++ Placement Course (Data Structures+Algorithm) : • C++ Full Course | C++... Telegram: t.me/apnikakshaofficial Instagram: / dhattarwalaman Notes of this Lecture:
Пікірлер: 356
@deepanshumahto80863 жыл бұрын
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-ov3fr3 жыл бұрын
Ys bro its absolutely correct because I m also facing same issue but now I got it 👍
@aryanttripathi3 жыл бұрын
@@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; } };
@rohandeshmukh39893 жыл бұрын
@@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
@rishavkumar63832 жыл бұрын
@@Rohan-ov3fr can pls upload the code here
@SaifAli-nt5sh2 жыл бұрын
@@anubhabray5254 probably you don't have all pointer checks in your conditional statement
@KrishnaGupta-xd6xu3 жыл бұрын
Aman bhaiya please make sure ki yeh course pura complete ho and Very thankful for your efforts for us ❤
@sauravchaudhary30643 жыл бұрын
I am loving this course, thanks for your efforts. Can't express my feelings in my words. Thank you so much
@talhamumtaz26782 жыл бұрын
Thanks aloooot didi, your way of teaching is mind blowing. Feeling blessed for being a student of APNA COLLEGE!
@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🙂
@darshantrivedi53903 жыл бұрын
Web development ka video plz🙏🙏🙏
@foreducation4082 жыл бұрын
this is such a good video spatially the part where she explained how to break the cycle.
@harshgupta26992 жыл бұрын
This is the best explanation of "detection and removal of cycle in linked list" i have come across. Thank you!
@ankitkumar-mi2of2 жыл бұрын
In which year u r ?
@anushkakumari5355 ай бұрын
I am in first year second sem
@codehustler85823 жыл бұрын
Great work sir plz continue 💯
@mohammadahsan78733 жыл бұрын
Very Well Explained. Thanks 👌❤️
@Chaitanya_64443 жыл бұрын
👍Thanks for the awesome playlist....
@yogeshsanap84533 жыл бұрын
Great explanation ! Thank You
@mhamza0163 жыл бұрын
Please upload web development next class
@harshpanwar15502 жыл бұрын
Hats off to u didi...... Explained in such a nice manner😄😄
@subratsahai20173 жыл бұрын
thanks bhiya and everyone associated with the project , the playlist has been a great help
@YashSharma-qo1sy3 жыл бұрын
Lectures are really world class,loved it.🙏🙏🙏🙏🙏🙏👍👍👍👍👍. PLS CONTINUE WEB DEVELOPMENT VIDEOS ALSO.
@Animesh0453 жыл бұрын
kzfaq.info/get/bejne/a7CalKpzyb-WeqM.html fdba
@nikheelindanoor30733 жыл бұрын
The code won't work if the loop starts at the first node itself
@satyamjaiswal59813 жыл бұрын
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
@majidmohd1003 жыл бұрын
Is this course going very slow? Not according to the timeline given ya?
@x_x35573 жыл бұрын
The above approach doesn't work when the loop is from the last node to the first node.
@jayprakashsaini6113 жыл бұрын
it works dear.
@tarunbisht80163 жыл бұрын
@@jayprakashsaini611 no the remove cycle doesnt work, tey urself u will lose all nodes except head after removing the cycle
@tarunbisht80163 жыл бұрын
@@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 ; }
@kushagra44013 жыл бұрын
@@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; }
@anuragpandey33413 жыл бұрын
@@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; } }
@shaantyagi21873 жыл бұрын
ha ha it is going into my head with very smooth way !
@yashverma70843 жыл бұрын
hats off to you guys explanation
@ashishsundriya6213 жыл бұрын
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.
@blizzardstorm97153 жыл бұрын
yes
@pendyalaabhishek88662 жыл бұрын
you should check for that case . keep a prev pointer to slow and when slow == fast at head prev->next ==NULL;
@hrithikjaysingpure96232 жыл бұрын
@@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.
@souravsarkar61073 жыл бұрын
Great Explanation Mam!!
@agamsingh86643 жыл бұрын
Sir has forgotten Apni Kaksha Password I think so😂😂😛😛
@rahulsheikh98016 ай бұрын
What an explanation it was ,,,,,,thanks a lot
@ramankr002211 ай бұрын
very helpful. thanks for uploading.
@gamingblast23253 жыл бұрын
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
@pranavmishra52113 жыл бұрын
apna college teachers are really good ngl
@utkarshawasthi33683 жыл бұрын
Felling first with 39 others 😂😂😂
@Kidzone12893 жыл бұрын
Kya aap funny videos or memes psand hai toh ye dekho kzfaq.info/get/bejne/bcqIdNuo25itkn0.html
@MusicLover-sd2hp3 жыл бұрын
*69 😎🤣
@harshitrathi30773 жыл бұрын
@Animesh 045 Disliking Your Video
@harshitrathi30773 жыл бұрын
@@Animesh045 Yaa and Even Thanks to My Group where i have share your video link to dislike
@Animesh0453 жыл бұрын
@@harshitrathi3077 thank you soo much beacuse vo sab aake video dekhenge even views badhyenge
@IronMan-fe8uf3 жыл бұрын
Welcome to apna comment section 😂😂😂
@prashantchakrawarti423 жыл бұрын
Thanku soo much 🙏🙏🙏 Finally DIDI JI🙏
@Animesh0453 жыл бұрын
kzfaq.info/get/bejne/hLqUnJaXmMCyaKM.html great t t !!
@rahul_ji213 жыл бұрын
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_Dhariwal3 жыл бұрын
#amandhattarwal #apnacollege Slow ho gye bhaiya course me 😐 Lamba break le liya aapne 😓
@jals4133 жыл бұрын
kzfaq.info/get/bejne/p5t-d9WYutPbf2Q.html Mast Edit kiya hai dekh lena ek baar Also leave a like and Subscribe
@rambabupatidar30923 жыл бұрын
For creating loop do put this in main() head->next->next->next->next = head ;
@rushikeshubale93012 жыл бұрын
Great explaination didi...!!
@vinayakd44443 жыл бұрын
Enable ads bhai. You are giving us so much of value. Please enable ads and also sponsorships. Thanks a lot!!
@prakharagarwal62373 жыл бұрын
To bhau donate kardo
@Sanidhya_Goyal3 жыл бұрын
Mann that proof deserves a Like!!!
@PepeTheFrog2016.3 жыл бұрын
Everyone is first untill they refresh
@shivammaurya34513 жыл бұрын
Thank u mam best explanation
@TrueSolutionsOfficial Жыл бұрын
this is very good explanation
@ShubhamKumar-gz5rr2 жыл бұрын
thank you for this video
@viraltoovideos Жыл бұрын
Nice explain mam thank you❤️❤️❤️❤️
@patalamrithish68382 жыл бұрын
Best Videp on DSA
@aashishjoshishorts3 жыл бұрын
Web development javascript kab aayega
@idrisbohra51763 жыл бұрын
Please upload the rest videos fast, we can't wait to complete the course . It is so good😜
@Animesh0453 жыл бұрын
kzfaq.info/get/bejne/hLqUnJaXmMCyaKM.html rtesh
@AnkitKumar-vd2dd3 жыл бұрын
When will this course complete?
@PrakashKumar-vr9wc3 жыл бұрын
It's help lot's of me
@vidyutphagetra38043 жыл бұрын
great explaination
@amoghmishra87452 жыл бұрын
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; }
@asishpanda35472 жыл бұрын
very well explained
@soumikmukherjee47973 жыл бұрын
can someone tell me why are we using do while loop in the remove function instead of the while loop?
@anushkakumari5355 ай бұрын
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
@NomadStriver3 жыл бұрын
excellent......
@codewithree9303 жыл бұрын
got it! :)
@UECAshutoshKumar Жыл бұрын
Thank you
@bhawnaaswani47773 жыл бұрын
it is very useful
@rutvikrana5123 жыл бұрын
Very nice explanation 💕
@jals4133 жыл бұрын
kzfaq.info/get/bejne/p5t-d9WYutPbf2Q.html Mast Edit kiya hai dekh lena ek baar Also leave a like and Subscribe
@starchamp46803 жыл бұрын
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.
@ideaindia42783 жыл бұрын
Sir please make a video on technical interview round how to crack it ?
@ssb6042 Жыл бұрын
one of the rare codes where i have seen use of do while😅
@saicharan46692 жыл бұрын
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_2 жыл бұрын
is this will work in case of circular ll ?
@arvindsingh.13873 жыл бұрын
How is the quality level of it...plz tell?
@pushparajbhutekar26773 жыл бұрын
Web development ka Lao yaar 😤 please bhaiya web development ka lao
@himanshu_________3 жыл бұрын
Yes brother mai v usi ka wait kr rha hun..
@jassmanakfan5553 жыл бұрын
Phle isee hi ho Jane de
@jals4133 жыл бұрын
kzfaq.info/get/bejne/p5t-d9WYutPbf2Q.html Mast Edit kiya hai dekh lena ek baar Also leave a like and Subscribe
@harshitrathi30773 жыл бұрын
@Animesh 045 Bro Tuh Jitna Yeh Link Dalega utna Dislike Milegah Isliyee Thoda Kaam Dal
@Animesh0453 жыл бұрын
@@harshitrathi3077 ok bro kitna dislike karloge
@tanmaysatsangi1313 жыл бұрын
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?????
@abhinavsingh97202 жыл бұрын
Thanks
@arjavkanadia97303 жыл бұрын
Even nodes(total) mei 2 nodes ke loop ke liye kaam nai karega (FYI)
@shubhamkale7353 жыл бұрын
when you realize you didnt do anything in your college times , linked list at another level Thank you
@pateldirgh31213 жыл бұрын
Sir when will web development class will be uploaded
@athleteprogrammer00733 жыл бұрын
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!!!!
@Animesh0453 жыл бұрын
kzfaq.info/get/bejne/a7CalKpzyb-WeqM.html rHRBH
@abhyudaypratapsingh43253 жыл бұрын
Love you mam ❤️❤️❤️
@AltafHussain-on2oe3 жыл бұрын
This code is not working for the testCase if cycle is forming at pos=1;
@manrajsandhu3 жыл бұрын
Waiting for Web Development Course
@rahulbajetha40573 жыл бұрын
is this code work for circular linklist???
@ishanidey95803 жыл бұрын
please kindly upload the notes and full codes also. i assume there are more like me who need them.
@InderjitSingh-sh9ve2 жыл бұрын
Khud bbnaalo
@prathamkumar37313 жыл бұрын
Aman bhaiya to coaching institute :biddu mera bacha hai tu 😂😂
@prathamkumar37313 жыл бұрын
@Animesh 045 krdiya subscribe
@thedreamballer3 жыл бұрын
Android course with Notes, please bhaiya
@ppriya12973 жыл бұрын
Bhai jo hai usko pehle padh lo yaar. Uske baad request karna Android development ka course.
@thedreamballer3 жыл бұрын
Mera kaam Android ka hai
@ppriya12973 жыл бұрын
@@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.
@thedreamballer3 жыл бұрын
I am not disrespecting anyone not even Aman Bhaiya but still I will write my suggestions in the comments
@udaypratapsingh89232 жыл бұрын
awesome
@pawananubhav123 жыл бұрын
thank you !!
@Animesh0453 жыл бұрын
kzfaq.info/get/bejne/a7CalKpzyb-WeqM.html FSb
@no_one31843 жыл бұрын
Plz upload a new vedio this code of removing loop is not working when loop is connected to first node🙏🙏
@rahulgoel55582 жыл бұрын
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; } } };
@prathamrana84333 жыл бұрын
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
@dharmeshpoladiya90473 жыл бұрын
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-nt5sh2 жыл бұрын
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
@khanresearchcenterunoffici3113 жыл бұрын
❣️🔥
@yashaswinisharma41853 жыл бұрын
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-xr6df3 жыл бұрын
yeah!
@74N2 жыл бұрын
Exactly
@itsaryanguys3 жыл бұрын
❤️🙏
@soni.himansh3 жыл бұрын
remove cycle function is not working for if the cycle is at a head node?
@dakshagarwal14633 жыл бұрын
ya man
@hanumansidh22873 жыл бұрын
Removing is not working when there is 5 element and loop starting from 1St element
@manmeetsinghchhabra39233 жыл бұрын
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; }
@amolsingh95383 жыл бұрын
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.
@sahilahmed55963 жыл бұрын
wahi bhai test case pass nhi ho rha isse
@utkarshnigam15733 жыл бұрын
the code is not working for all test cases .Please help.
@adarshmishra81983 жыл бұрын
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
@afsanVlog11003 жыл бұрын
you are right @adarsh mishra ,I also tried
@008abhishekvishwakarma93 жыл бұрын
I also stuck in the same situation...help me please
@adarshmishra81983 жыл бұрын
@@008abhishekvishwakarma9 bro you can add an extra condition regarding this situation or you can solve this problem using map to..
@zaveriamutwalli63993 жыл бұрын
Why node* &head and not node* head in detect cycle function
@jitengarg57403 жыл бұрын
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. :)
@jiosim13773 жыл бұрын
This is not to find middle element.its just to detect if a cycle is present
@sumitsingh-gn4ed Жыл бұрын
may be remove cycle will not work if both slow and fast pointer will meet at loop node.
@MOHANKALYANI-lf9xt Жыл бұрын
why did they use the do while loop , @apnacollege please explain
@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
@sharansai7923 жыл бұрын
You guys did not mention the exception case.
@AnkitKumar-vd2dd3 жыл бұрын
When will this course complete?
@Animesh0453 жыл бұрын
kzfaq.info/get/bejne/a7CalKpzyb-WeqM.html FDHBFR
@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
@deepanshukumar72903 жыл бұрын
agar cycle head pe hu toh fast slow head pe he aa jaege ?????????????