Why Floyd's cycle detection algorithm works? Detecting loop in a linked list.

  Рет қаралды 114,180

Vivekanand Khyade - Algorithm Every Day

Vivekanand Khyade - Algorithm Every Day

Күн бұрын

Пікірлер: 257
@bharaniakella7734
@bharaniakella7734 7 жыл бұрын
This guy should be a youtube celebrity! People like him who share knowledge should be made famous.
@jackzhu6482
@jackzhu6482 4 жыл бұрын
can't agree more, very well explanation!
@kingdey9136
@kingdey9136 4 жыл бұрын
he is a celebrity already
@sarvodaykumar2723
@sarvodaykumar2723 3 жыл бұрын
Must be
@Photon7908
@Photon7908 6 жыл бұрын
I guess one minor point that I couldn't find in his video is this: (m+k) = integer*l -> this means, if you have p at the kth node and q at the start, by the time q travels m+k nodes from the start, p will finish one complete revolution on that loop. i.e., p and q will coincide at the kth node again. But if q only travels m nodes, p has travelled only (integer*l)- k nodes as well. So if p started at the kth node, and q at the start, they will meet at the start of the loop. (I hope this makes sense as it does in my head lol) Thanks for the video Vivek!
@vaibhavrbs
@vaibhavrbs 5 жыл бұрын
``But if q only travels m nodes, p has travelled only (integer*l)- k nodes as well. So if p started at the kth node, and q at the start, they will meet at the start of the loop.`` can you explain this part again please, this is not clear to me,
@untwaddle
@untwaddle 5 жыл бұрын
@@vaibhavrbs p has already made k steps from the start of loop so to reach the start point again, it should travel (int * l) - k. it equals that q will make only m steps to reach the start point. other words, we had equation: m + k = int * l and then we subtract k from both sides. equation is still correct, now q will make m steps to reach the start point and at this place it will meet p. (p made (int*l)-k steps)
@sadmansakib007
@sadmansakib007 4 жыл бұрын
You are absolutely right. Something was missing in that video but THAT"s the main point!
@mhp3bozis
@mhp3bozis 4 жыл бұрын
Honestly think THIS should be the main focus, thanks for pointing out
@kaustavgalacticos
@kaustavgalacticos 4 жыл бұрын
You missed one minor key point as well, ASSUMING q is equal to p after q starts from 0 and p starts from k, and *your rest of the logic*.
@pankaj_2024
@pankaj_2024 6 жыл бұрын
worth spending 24 minutes , good work.
@ashwanigupta5412
@ashwanigupta5412 4 жыл бұрын
Hi Vivekanand sir, can't thank you enough for making this video. I have seen almost half a dozen videos on this online and after this I can understand the logic behind it fully. Worth spending 24 minutes. Kudos to you!
@robb1931
@robb1931 4 жыл бұрын
Finally, there's a video that helps me understand this algorithm. Thanks a lot!
@rehaanredkar1489
@rehaanredkar1489 4 жыл бұрын
this man is unbelievable , the way he explains is just mind blowing
@leolin5479
@leolin5479 4 жыл бұрын
You really save me from struggling with the textbooks and any other recourses I could find, thanks !
@KM-star
@KM-star 5 жыл бұрын
OMG! This is the 1st video I am watching of this person and I am in love with his way of explaining things! I hope the rest of his videos are equally good. I can now recollect some friend recommending this person's videos. @Vivekanand ...You definitely have a fan base!
@Dontpushyour_luck
@Dontpushyour_luck 2 ай бұрын
best video. I never understood this algorithm's proof properly but this was an excellent explanation
@da_sci3839
@da_sci3839 3 жыл бұрын
1. Best explanation I've found to describe this! No other explanation made sense. 2. I love the way you say "loop" XD.
@algorithmimplementer415
@algorithmimplementer415 3 жыл бұрын
I am convinced that I understood the explanation. Thank you!
@intechshala5929
@intechshala5929 3 жыл бұрын
kyaa bataya hain aaapne jo koi na samgha saka aapne samgha diya bohot sahi
@___vandanagupta___
@___vandanagupta___ 4 жыл бұрын
your teaching style is amazing ! i dont know why u dont have million subs
@danielstatler954
@danielstatler954 Жыл бұрын
after a couple rewinds, i finally got it. i doubt i could ever come up with this algorithm on my own. good vid
@jeezz4128
@jeezz4128 3 жыл бұрын
I didn't see such a clr explanation ever .... keep going sir
@ananyaarya2465
@ananyaarya2465 3 жыл бұрын
Thank you so much
@saravanansarangan7035
@saravanansarangan7035 5 жыл бұрын
I got same confusion after seen the solution on leetcode. How they meet eachother at the beginning of the cycle but now it is clear. Thanks Viveka you are great...
@kirthanasingh635
@kirthanasingh635 3 жыл бұрын
Your Explanation is amazing Sir!! Keep making videos
@ngc35ster
@ngc35ster 2 жыл бұрын
Thanks man, this is way more clear than the leetcode answer
@mariammohamed176
@mariammohamed176 2 жыл бұрын
Thanks, it is the best explanation I have seen so far
@caio-jl6qw
@caio-jl6qw 3 жыл бұрын
WOW, very very VERY good explanations, thank u for these videos !!!!!!!!!!!!
@kbhoyi
@kbhoyi 3 жыл бұрын
OMG - Such a beautiful explanation! I'm listening to Vivek Sir's video first time. I'm sure, I'm in for a treat when I will search for other videos of his teaching. Stay blessed Sir.
@rohitkumarvarma4952
@rohitkumarvarma4952 3 жыл бұрын
Thanks, mann! Finally understood this concept clearly!
@ankitvishnoi8670
@ankitvishnoi8670 5 жыл бұрын
I really enjoy your videos and your videos are helping a lot of people as we. I recommended your channel to many of my colleague and college friends. Keep up the good work. ;)
@amitvaghela1456
@amitvaghela1456 4 жыл бұрын
Great simplified explanations.
@aterribleyoutuber9039
@aterribleyoutuber9039 2 жыл бұрын
Thanks a lot! I was struggling to understand this at first!
@chrisdanan2183
@chrisdanan2183 2 жыл бұрын
Wonderful explanation - thank you very much.
@denys_kovpaka
@denys_kovpaka 2 жыл бұрын
I like the way you explained this. Thank you a lot)
@SoumikNandi
@SoumikNandi 4 жыл бұрын
One Point to mention.!! Rather than saying that Distance of P traveled would be Double the Distance of Q because "P's speed is twice than that of Q" kind of makes it incorrect statement. What we can explain is Let's say they start their journey at time T = 0. Now when they meet the time elapsed would be equal (Why? Because the time frame is absolute. Doesn't matter how they move they will meet only when they are in the same position at the SAME TIME) So, we know S = D/T (Speed = Distance/Time which also means T = D/S), from the equation we can say Tp (Time taken for P to reach the meeting point) = Tq ( Time taken for Q to reach the meeting point) or (m + pl + k)/2 = (m+ql+k)/1 Now work up to get, ---> (m+k) = l * (p-2q) NOTE: Another thing worth noting is that (2q-p) is also an integer but it'll never take the form of (2q-p) (Why? Because the left-hand side has a dimension of length (scalar) and hence cannot be negative).. Now, why is that (2q-p) is likely to be negative? Because P's speed is greater than Q. So its likely that P would travel the loop more number of times than Q will Hence, p > q/2 --> (Why q/2 ? follows from the above discussion) Or, (p - 2q) > 0 but (q-2p) < 0 It was just a suggestion!. The explanation is wonderful. It's just a part where I felt needed a little bit more clarification
@shashankmehul02
@shashankmehul02 4 жыл бұрын
Such wonderful explanation.Very helpful.
@lokeshjaliminche
@lokeshjaliminche 5 жыл бұрын
Good to see you after a long time! Great work. Good going!! :)
@remmargorpp
@remmargorpp 4 жыл бұрын
Bestest explaination ever!
@liangchen8238
@liangchen8238 4 жыл бұрын
Best explanation I've seen so far!
@tushargarg3765
@tushargarg3765 3 жыл бұрын
Thanks for such a Nice Explanation.
@konstantinrebrov675
@konstantinrebrov675 4 жыл бұрын
Indian professors are awesome!
@anubhavsinha8048
@anubhavsinha8048 4 жыл бұрын
Very nice explanation!
@akki4u
@akki4u 6 жыл бұрын
Your explanation is so good that makes learning easy. Great work my friend!
@jaibhambri6853
@jaibhambri6853 3 жыл бұрын
Very Nice Explanation
@omkar.at.office
@omkar.at.office 2 жыл бұрын
Awesome explanation! Thanks 🙏
@KhanSlayer
@KhanSlayer 6 жыл бұрын
Very clear and concise explanation. Nice work.
@secretman1787
@secretman1787 3 жыл бұрын
Excellent explanation !!!
@columbiars
@columbiars 7 жыл бұрын
Wow, excellent explanation dude! I was trying to figure out why this algorithm worked, and finally I found the right answer. Keep going this videos!
@moghalsalwar6803
@moghalsalwar6803 Жыл бұрын
I feel bore even for 10mins video ..but I didn't feel bore this tym when I am seeing this particular video...Thank U Sir
@mp0157
@mp0157 5 жыл бұрын
This is the best video dealing with Floyd's Cycle Detection Algorithm out there! Vivekanand, hats off to you for making this explanation so simple and straightforward! Thank you :)
@robertr6054
@robertr6054 4 жыл бұрын
Just a minor point. When you’re doing the difference step you can just look at (m+k)=L*P. 2q will always be 0, as for any sized loop q will never be able to complete a full rotation before p catches up to it. P will also never be able to skip over Q in a loop. You can look at the most favorable example, if q enter the loop as p has just skipped over it. Before q will be able to traverse the rest of the loop to make a full rotation p will already have done so and be equal to q.
@learningpool5918
@learningpool5918 3 жыл бұрын
This man is gold. But I like watching it at 1.75x speed
@ashishdukare1313
@ashishdukare1313 4 жыл бұрын
Awesome explanation Sir : )
@ayushsakure6098
@ayushsakure6098 2 жыл бұрын
Very well explained.
@loba8924
@loba8924 2 жыл бұрын
Thanks. Nice explanation
@arpitamandal6469
@arpitamandal6469 3 жыл бұрын
thanks for explaining it so well..
@jamesclark1207
@jamesclark1207 4 жыл бұрын
Really excellent explanation - thank you
@mahipalsingh-yo4jt
@mahipalsingh-yo4jt 4 жыл бұрын
very well explained thank you..............................
@isaacc9487
@isaacc9487 3 жыл бұрын
This is very clear and detailed, thanks a lot.
@karanb2067
@karanb2067 5 жыл бұрын
heroic explanation
@mangeshgupta5677
@mangeshgupta5677 4 жыл бұрын
Great explaination thank you
@blackswordsman9745
@blackswordsman9745 6 жыл бұрын
Your videos are really helpful. Thanks a lot for making them :)
@DurgaShiva7574
@DurgaShiva7574 4 жыл бұрын
you are seriously amazing bro...i love your knowledge and teaching way, keep up the good work..
@shubhamjadhav2656
@shubhamjadhav2656 4 жыл бұрын
very well explanation!
@adityasingh11156
@adityasingh11156 5 жыл бұрын
Thanks Sir You make it understand in very simple way
@devtorch
@devtorch 4 жыл бұрын
I am on my knees and have tears in my eyes :)
@jamietherooster
@jamietherooster 7 жыл бұрын
You are very good, I am english but find your videos far clearer than any native english speaker's video's. How do you gain the knowledge of these algorithms ? do you have a book ? I purchased 'introduction to algorithms' but find it very technical and hard to understand.
@sharansrivatsa210
@sharansrivatsa210 5 жыл бұрын
Honestly, I think its just going through this book called CLRS and preparing by just looking at more and more problems and how to solve them If you go to leetcode.com and start solving I'm sure you will start to get an intuition Also, these are algorithms that are used and proved. Its a lot about just learning these. geeksforgeeks is a good resource too.
@rahulchudasama9363
@rahulchudasama9363 4 жыл бұрын
Nice explanation ...
@mahesh23343
@mahesh23343 4 жыл бұрын
Boy is son of mother. Mother is mother of boy. Man is husband of mother. Mother is wife of man. You can go to Delhi from Punjab. You can also go to Punjab from Delhi!! This video could be easily completed 5-6 minutes earlier if he wasn't repeating everything so many times! But got the concept clear, so thanks. But please try to be a little faster than this. God bless youtube developers for creating speed control.
@blasttrash
@blasttrash 3 жыл бұрын
install video speed controller extension. it allows you to go beyond 2x speed.
@mahesh23343
@mahesh23343 3 жыл бұрын
@@blasttrash noted.
@davidtheprogrammer
@davidtheprogrammer 2 жыл бұрын
Thanks so much. I wish we could derive floyd's cycle algorithm instead of assuming it's correct and making the assumptions from there.
@vedvish3916
@vedvish3916 3 жыл бұрын
Really awesome explanations,thank you.........,If possible please makes a playlist on stacks and queue.
@vivekanandkhyade
@vivekanandkhyade 3 жыл бұрын
Sure.
@kishantiwari3221
@kishantiwari3221 4 жыл бұрын
Thank You sir!
@codestorywithMIK
@codestorywithMIK 4 жыл бұрын
Let us suppose the length of the list which does not contain the loop be s, length of the loop be t and the ratio of fast_pointer_speed to slow_pointer_speed be k. Let the two pointers meet at a distance j from the start of the loop. So, the distance slow pointer travels = s + j. Distance the fast pointer travels = s + j + m * t (where m is the number of times the fast pointer has completed the loop). But, the fast pointer would also have traveled a distance k * (s + j) (k times the distance of the slow pointer). Therefore, we get k * (s + j) = s + j + m * t. s + j = (m / k-1)t. Hence, from the above equation, length the slow pointer travels is an integer multiple of the loop length. For greatest efficiency , (m / k-1) = 1 (the slow pointer shouldn't have traveled the loop more than once.) therefore , m = k - 1 => k = m + 1 Since m is the no.of times the fast pointer has completed the loop , m >= 1 . For greatest efficiency , m = 1. therefore k = 2. if we take a value of k > 2 , more the distance the two pointers would have to travel.
@bittuxoxo
@bittuxoxo 4 жыл бұрын
sir yur vvideos are the best..i really get to understand how yu teach good one sir .i will be hoping for a recursion video explain it in depth
@null-wp1le
@null-wp1le 4 жыл бұрын
Thank you so much for this video.
@najimahmed8923
@najimahmed8923 5 жыл бұрын
#suggession: Complexity analysis would make the series complete. Please do another video to do complexity analysis!!! Great analysis! Thanks much!
@truthprevails899
@truthprevails899 4 жыл бұрын
Thanks for the explanation!
@chakrapanisudarshan3027
@chakrapanisudarshan3027 7 жыл бұрын
Brilliant Explanation in simple words.....
@vivekanandkhyade
@vivekanandkhyade 7 жыл бұрын
Thanks Chakrapani.!
@asgheralishaik
@asgheralishaik 4 жыл бұрын
nice explannation.Thanks
@AMARSINGH-lj4rd
@AMARSINGH-lj4rd 4 жыл бұрын
great explanation , thanks you saved me viveka !!! :-)
@ShwetaNaganath
@ShwetaNaganath 7 жыл бұрын
Thank you. i was struggling with this since long.
@krisnadiputra93
@krisnadiputra93 4 жыл бұрын
This guy has just saved me from a sleepless night lol
@ankitvarmait
@ankitvarmait 6 жыл бұрын
Thank you for wonderful explanation
@azam148
@azam148 6 жыл бұрын
Very clear explanation!
@yys3082
@yys3082 3 жыл бұрын
Now, I know how it works. Thanks
@elizkotadia9350
@elizkotadia9350 7 жыл бұрын
Great Job !!! Crystal clear explanation !!
@kbhargavi4400
@kbhargavi4400 4 жыл бұрын
thank you, sir, you explained such a confusing concept very well! :)
@neeraj33negi
@neeraj33negi 4 жыл бұрын
Thanks, this is very detailed.
@glassanddiaphane
@glassanddiaphane 4 жыл бұрын
This is awesome, this really helped me to finally understand it, thank you.
@ShivamKendre-fc3su
@ShivamKendre-fc3su 4 жыл бұрын
What a explanation!!!
@anandkulkarni2111
@anandkulkarni2111 7 жыл бұрын
doing good job!! excellent work keep them coming !!!
@vivekanandkhyade
@vivekanandkhyade 7 жыл бұрын
Thanks Anand..!
@apiltamang2767
@apiltamang2767 5 жыл бұрын
props for setting up the video. I think it'd help your videos tremendously if you prepared your speech in advance on the idea you're talking about, and especially so for a convolved topic like this, rather than just give an impromptu performance. I think that would help the video be more concise, and perhaps even better explained. Regardless, first time learning this material and I think I understand it just fine. So you must have done it right, albeit with some effort :)
@yuhaodai5795
@yuhaodai5795 5 жыл бұрын
Nice explanation!
@gugliamo
@gugliamo 2 жыл бұрын
this was great, thank you!
@chienhsiang-hung
@chienhsiang-hung 2 жыл бұрын
you deserve more subs
@surendrapandey4660
@surendrapandey4660 2 жыл бұрын
This video doesn't show up in top searches of the topic. It makes me think youtube algo is not working properly
@dragosc8202
@dragosc8202 3 жыл бұрын
Thanks! YOU make my day
@pratiknaik261
@pratiknaik261 2 жыл бұрын
Thanks sir ek no!!💯💯
@abhishekshrm100
@abhishekshrm100 6 жыл бұрын
very nice explanation
@farabikurmanshady8486
@farabikurmanshady8486 5 жыл бұрын
Clear explanation! Thanks!
@aynurmukhambetova1708
@aynurmukhambetova1708 4 жыл бұрын
it finally became clear! thanks a lot!
@pratikghorpade6853
@pratikghorpade6853 6 жыл бұрын
Thank you sir ..... Great explanation ....
@mohan-ri6ze
@mohan-ri6ze 3 жыл бұрын
Understood well
@LogEekumanAgination
@LogEekumanAgination 6 жыл бұрын
That was beautiful and made me happy thank you so much
@praveenchouhan6388
@praveenchouhan6388 4 жыл бұрын
awesome work thanks a lot!!!!!!!!!!!
@NarendraKolink
@NarendraKolink 5 жыл бұрын
really helpful... Thanks a lot
Delete a node from Doubly Linked List(start / middle/ end node)
8:35
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 85 М.
Segregate 0's, 1's and  2's together in an array[O(n)](Dutch National Flag Problem)
17:27
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 61 М.
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 20 МЛН
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 9 МЛН
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 8 МЛН
Yay😃 Let's make a Cute Handbag for me 👜 #diycrafts #shorts
00:33
LearnToon - Learn & Play
Рет қаралды 117 МЛН
L14. Detect a loop or cycle in LinkedList | With proof and Intuition
20:26
Elementary school homework in China
9:08
MindYourDecisions
Рет қаралды 54 М.
Detect loop in linked list(floyd algo / Tortoise and hare algo)
9:29
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 112 М.
The Minecraft Movie memes are way too good.
8:10
Phoenix SC
Рет қаралды 1,1 МЛН
206. Reverse Linked List | Iterative & Recursive
25:51
Aryan Mittal
Рет қаралды 1 М.
Programming Anime: Floyd's Algorithm Explained
19:44
JomaClass
Рет қаралды 269 М.
Interview Question: Start of Loop in a Linked List
10:37
Gaurav Sen
Рет қаралды 144 М.
Circular Linked List in Data Structures (with Code)
21:46
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 52 М.
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 20 МЛН