I really like the way you explain the algorithm, so calm and straight to point
@leopoldroitel40225 жыл бұрын
So basically unless you know Floyd's algorithm, you can't come this up with this by yourself.
@GKALYAN044 жыл бұрын
Btw, You can use Hash Tables which has the same time complexity as Floyd's algo.
@the_chi4 жыл бұрын
@@GKALYAN04 but not the same space complexity
@krisnadiputra934 жыл бұрын
lol, it s not true, at least Floyd could
@TonyDemetriou4 жыл бұрын
You probably could come up with it yourself if you are thinking about it the right way. For me, if I think about a loop where I want to walk around it and stop on the same square I started on, then I would probably want to use the second pointer to stay still and when they're equal again we have reached the start. If you then said I have to move both pointers I might think of moving the second one at double speed so it will do two loops and be at the start when the first pointer reaches the start. After that, I can figure out how to start with a chain that becomes a cycle, but they wouldn't meet at the right square, and I'd think about how with the loop I started both pointers together, but with the chain one pointer has a headstart by the time the other starts on the loop. If the headstart is 2, then it will meet up 2 steps too early. That would tell me that the number of steps to the start of the loop is the same as the number of steps in the chain, but I don't know what that number is. But if we take the same number of steps along the chain and the remaining loop we will meet at the start of the loop. Then I would think about unusual situations, like when there's an even vs odd number of steps, or what if the chain is much longer than the loop, or the loop is much longer than the chain. ... So I'd probably get to the right answer, but ONLY because of the way I started thinking about it, and because of the questions getting asked. If I was just programming and wanted to loop around to the start, then I wouldn't need to move the second pointer, and I wouldn't be thinking about the rest and wouldn't figure out that you can detect cycles like this. Or if you just gave me a list of nodes and asked me to check if there are cycles, I'd probably start thinking about starting from the beginning of the chain rather than starting with the loop, and I personally probably would not figure it out. People trained in formal mathematics have ways of working through problems like this. I'm unfortunately not one of them - for me, a lot of the time it's whether I'm asking myself the right questions, and that is usually just luck depending on where my mind wanders at that particular moment.
@karana22604 жыл бұрын
if you jog with people in a park, or watch f1, you could come up with this solution.
@Artshi_Sakshi3 жыл бұрын
sir ,the way you explain makes it so easy to understand......kudos to your effort!!!!
@lifekool58382 жыл бұрын
Such a simple yet powerful explanation of various algorithms. I hated algos... but now it is fun due to your videos and your positivity is icing on the cake. Thank you sir... for amazing videos.
@shashankparmar78994 жыл бұрын
Great solution sir!!! I have always used unordered map for this. (unordered_map map). But, this solution is very elegant and also requires only O(1) space complexity, unlike unordered_map solution.
@Cybernetic15 жыл бұрын
Sir, I have big fan of yours..... i love the way you explain... the way you talk slow and simplicity in your face.
@mp01575 жыл бұрын
Vivekanand, You kept the explanation quite simple & straightforward! It greatly helped :) Thank you!
@shivamrajput33214 жыл бұрын
the way you explain is very easy to visualize and implement. even a guy like me who gets bamboozled seeing these algorithms is able to keep up. Nice going bro. Hoping for your prosperity
@nareshtanniru5 жыл бұрын
Thanks For video. To find start of loop here is another alternative after p and q meet. we will make q pointer stop at that point and make p pointer move till it reaches q pointer again and count number of nodes in loop. this will give us length of cycle. ( how many nodes are in cycle). lets denote dis with c. then just take 2 pointers p1 and p2 at c distance apart.. and move both at SAME speed till p1 and p2 meets. that point will be start of loop.
@zippy.gaurav5 жыл бұрын
Thank you for posting your videos free of cost. I really am thankful to you.
@PaulFromMalta4 жыл бұрын
REALLY AWESOME EXPLANATION!!! Thank you so much for taking the time to make this video. 9 mins and 28 seconds of no bullshit, and just fundamental basic concepts built on top of each other in a crystal clear way. Please keep making vids!!!!
@joemoe59547 жыл бұрын
Thank you! This helped me understand how to detect a loop within a link list quickly and in an understandable manner!
@vivekanandkhyade7 жыл бұрын
Thanks Joseph...!
@adityapaithon64996 жыл бұрын
What's the time complexity of this approach
@vaibhavlaxman49592 жыл бұрын
@@adityapaithon6499 O(n)
@fahim.m.choudhury4 жыл бұрын
Thank you very much! Your explanation and teaching are very clear.
@gin89644 жыл бұрын
Very straightforward explanation. Thank you so much!
@chunkwanchan550311 ай бұрын
Thanks! can I start p pointer at head & q pointer at head.next? I found in some cycle structure, there's infinite loop where 2 pointers will never meet?
@poojaupadhyay63644 жыл бұрын
very clear and concise explaination
@krisshore29175 жыл бұрын
Simplest explanation for this algorithm. Thank you.
@crazyvlog58303 жыл бұрын
🎂🎂🎂🎂🎉🎉🎉🎉🎉🎂
@RadhamaniRamadoss2 жыл бұрын
Loved the explanation ..Thankyou sir
@cppdog35492 жыл бұрын
To find the start of the cycle, skip to 6:00
@sudomoon4 жыл бұрын
Simply Wonderful Explanation
@varnanthirugnanasambandan5592 жыл бұрын
Very clear explanation 🙏
@nahidulislam90003 жыл бұрын
Your video is much more understandable than others.
@nouru68566 жыл бұрын
@Vivekanand your the best!!!! Thumbs upppp
@gawarivivek6 жыл бұрын
I'm loving your videos, man!! Clear explanation.. Thanks for sharing your knowledge with us.. Keep it up!!
@kewtomrao4 жыл бұрын
Why the haters?So nicely explained......Keep it up!
@prajwalcr77993 жыл бұрын
How will be the linked list already present in our IDE as we are directly checking instead of inputting anything
@vinaynadig32587 жыл бұрын
simple but perfect explanations. Liked it
@jh91045 жыл бұрын
Super clear explanation of the concept. Thank you!
@mihirjoshi35896 жыл бұрын
Your videos are very helpful. Could you please make one for LRU Cache? Superb initiative, thanks a lot!
@DarshanKumarTV-ur8tw10 ай бұрын
satisfactory teaching sir
@smritidubey57813 жыл бұрын
Sir, why q->next!=NULL is considered in the while loop?
@bisatisrilatha79573 жыл бұрын
TQsm sir it was very helpful vedio.
@PriteshRanjan306 жыл бұрын
you have very nicely explained this solution.please Provide dynamic programming video explanation with examples
@karthikeyaacharya84244 жыл бұрын
Awesome and simple explanation !!
@angelroma54563 жыл бұрын
Thank you bro, pretty simple to understand!
@trestenpool90453 жыл бұрын
Great explanation sir, thank you!
@sankaranarayananh79575 жыл бұрын
Awesome explanation sir! Thank you
@akshayroy62614 жыл бұрын
Great Explanation 😀
@hemantmangwani71724 жыл бұрын
Thank you sir . Its Helped a lot.
@AbhishekSharma-uh8pb3 жыл бұрын
When you starting again sir . Very good 👍 explanation
@HarmeetKaur6 жыл бұрын
Thank you for these videos. Really helpful!
@priyanshuyadav81733 жыл бұрын
You're a great teacher ✨✨
@Ankit135557 жыл бұрын
Can you please explain Brent's Cycle Detection Algorithm ..that will give an edge in interviews
@anshiknigam6717 жыл бұрын
while(p && q && q->next) why only we are checking q->next. should we also place p->next also. please clear the doubt, is it important to place q->next in this condition. I think that p && q is enough. if I am wrong please correct me, anyone.
@nands44106 жыл бұрын
Anshik Nigam q is ahead of p by one step so we need to check for q itself.
@pavankumard52765 жыл бұрын
wont this show an error if there is no loop and the linked list consists of 4 nodes. because then p&&q&&q->next is not null but q->next->next=null it will show exception in java
@AjinkyaWasnik5 жыл бұрын
Perfectly explained. Whatever questions aroused while watching the video were answered right then and there. :) keep posting videos, sir.
@jeevan999able4 жыл бұрын
*arise
@lotusithok49857 жыл бұрын
Best explaination so far...
@xof82565 жыл бұрын
Mast bhava, dhanyawad
@anirudhbharti30134 жыл бұрын
I think for remove_loop while(p->Next!=q->Next) should be the condition
@vighneshk5094 жыл бұрын
sir in while loop you said anyone of those condition but that is AND operator so all condition must be satisfied not just one of them
@simonwathigo6044 жыл бұрын
I think it was just a mistake. Having a nil value will raise an runtime error `cant access next attribute for 'nil' value`.
@ayushikumar346 жыл бұрын
Thanks a lot for a great explanation .. keep up your good wrk ... you are really good
@sunnyjain6306 жыл бұрын
very nice expland should we have p=p->next and q=q->next->next in case of removal of loop detected by detection algo in step1 plz clear my doubt any one.... thanks in adv
@nands44106 жыл бұрын
I am no expert but I would maintain a previous pointer to p say "previous" and when we detect the start of loop i would set the previous-next->NULL. This would remove the loop.
@ayushikumar346 жыл бұрын
yes true ..what is written on board is wrong ..probably coz of which he didnt explain ...it shud be q->next->next
@AddieInGermany7 жыл бұрын
Sir i cannot find Floyd Algo.. Can you please provide the link ?
@srinivasanshanmugam95276 жыл бұрын
Pls post the video for reversing the doubly linked lists
@kingdey91364 жыл бұрын
Thank you!
@chhamasahu59877 жыл бұрын
Hello ,sir can you give us the link for the explanation on why this algorithm work.I couldn't find it on your channel.
@vivekanandkhyade7 жыл бұрын
"Why floyd's cycle detection algorithm works? " on this channel. Please check. Thanks.
@ranjanasinha5 жыл бұрын
Loved it. Thanks a lot.
@hitec16915 жыл бұрын
India!! :)
@santoshreddy99633 жыл бұрын
Sir slow pointer null condition check karne ki zaroor nhi he.
@kanakadasyankor7 жыл бұрын
Hi Vivek .. Awesome..thanks a lot.. any videos on Graphs ?
@vivekanandkhyade7 жыл бұрын
Thanks Kanakadas.......sure will soon start a series on Graphs...!
@rashmikiranpandit89624 жыл бұрын
I hit subscribe cuz your innocent way of asking us to subscribe was so cutee..:)
@madhavikatta73464 жыл бұрын
Thank you sir
@arvindkumarsharma55365 жыл бұрын
Well explained as always..
@ankurrohilla46554 жыл бұрын
Sir,why u stop uploading videos!!!!!!!!! u r the best
@anandkulkarni21117 жыл бұрын
10 /10 explanation kudos!!
@anilkumaryadavchimaldhari76953 жыл бұрын
Simply super
@karynayehorova6065 жыл бұрын
Awesome. Thank you.
@ShivamKendre-fc3su4 жыл бұрын
Greay explanation!! keep it up
@mannankathuria88795 жыл бұрын
Count the number of nodes in a link list program please
@mainulhasan1364 жыл бұрын
You are too good..
@deepakborah83356 жыл бұрын
Congratulations for making good video. Upload videos series on Merg,Quick and Radix sort algorithm and program.
@engineersride82737 жыл бұрын
Hello Vivekanand, please do upload a video on how to remove the loop from linked list
@vivekanandkhyade7 жыл бұрын
very sooon...! Thanks..!
@jeeveshrawal25767 жыл бұрын
Plz can u explain detection of loop in doubly linked list
@jaysahu3577 жыл бұрын
Very nice sir
@chandralekha77176 жыл бұрын
Great video thanks
@RahulKumar-qu1if4 жыл бұрын
Sir what is the time complexity of this prog.
@vishalvikram86374 жыл бұрын
O(n)
@Jarikraider6 жыл бұрын
You probably want to ensure that q->next and q->next->next are not null in that order.
@mritunjaymishra50084 жыл бұрын
If there isn't a loop...then won't it run infinitely?🤔
@amanbajpai95133 жыл бұрын
it will null terminate
@fares.abuali2 жыл бұрын
Thanks ❤
@gunjankumar79707 жыл бұрын
sir plze upload some important programming interview questions of binary search tree ....it's being difficult to understand due to recursion
@anuragsahoo12353 жыл бұрын
let just say there is cycle between two node then it is better to check first then iterate.
@anilbharath19947 жыл бұрын
It's really helped me a lot
@vivekanandkhyade7 жыл бұрын
Thanks Anil...!
@ill-fatedstranger4476 жыл бұрын
Many many thanks
@sudhak85695 жыл бұрын
Sir i cannot find full code in github...Can you please provide the link ?
@induroopa6276 жыл бұрын
Thanks a ton 👍🏻😍
@srinivasanshanmugam95276 жыл бұрын
Also please post detecting loop in doubly linked list
@carlosalba96905 жыл бұрын
This amazing!!!!!!
@musicmania46096 жыл бұрын
Good job
@vishnuvardhan-md1ux7 жыл бұрын
bro please post more videos thank you for your videos and the help
@payalsagar18084 жыл бұрын
great🙌
@uvenkatasaiswaroop24255 жыл бұрын
Boss , You r Awesome !!!
@Kaushikvel7 жыл бұрын
If you don't understand from this video, you will never understand from anywhere else.
@mayank.ranjan6 жыл бұрын
true
@adityapaithon64996 жыл бұрын
What's the time complexity of this btw
@pymondo11476 жыл бұрын
hahaha absolutely true.. No one can give this much explanation. If people are still finding it difficult then they should find other jobs:-p
@aakash.nagpal985 жыл бұрын
land le
@aarushiahuja38756 жыл бұрын
Sir kindly explain the program of this topic you have provided on github , thank you in advance :)
@ankitvarmait6 жыл бұрын
Thanks Sir
@dhritisinha83774 жыл бұрын
Narsimha karumanchi ki book ka exact code chapa h
@AddieInGermany7 жыл бұрын
Sir where is the next video, i can't find it.
@vivekanandkhyade7 жыл бұрын
Hey I am sorry Aditya...I forgot to upload the video...I will upload the video soon...!
@AddieInGermany7 жыл бұрын
No problem sir. I found the solution on geeksforgeeks.
@MrPraveenBasavaraj7 жыл бұрын
where is ur next video. can't find
@vivekanandkhyade7 жыл бұрын
"Why floyd's cycle detection algorithm works? " on this channel. Please check. Thanks.
@graingert6 жыл бұрын
"I will execute the code parallely": *executes code sequentially*