Data Structures: Cycles in a Linked List

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

I love how easily and swiftly she explains and walks through the code. Thanks Gayle!!

singh
Автор

i love how those cars just drove away loll

sergiip
Автор

Your abstracting the solution to a concept as simple as a race car lapping another is brilliant. I'll try to think like this in the future!

dhanushkalangi
Автор

You can still do the first technique even if you can't modify the linked list itself. Just use the pointer value as a key into a map, and the value is whether it is seen or not.

trampflips
Автор

Back in 2008 in my first Maya class the teacher tried to tell us about how two different objects moving at different speeds would eventually pass each other by if they're travelling the same path back and forth and I didn't understand it so he showed it to me in Maya. That was the same idea as the algorithm here. Thanks.

MrZZooh
Автор

Leave it to Hackerrank to explain the concept. A bit confused in the first 3 indexes, but this is the best explanation of the process on YouTube.

TraceguyRune
Автор

Thank you. This was an amazing tutorial which gave me ground root fundamentals. You have a great way of expressing and following through your code. In fact, I did connect this linked list video not just for code I was writing a framework in Swift (Graphs and Matrices), but also for an circular linked list assignment in my Operating Systems class, Linear Algebra a bit conceptually and definitely for cryptography class (check pollard rho algorithm) plus this will come back for a month long crypto project if I pull through on the exam this week. I'll be sure to tune into more of your videos! :)

tahirvali
Автор

I want to see this with more test cases. If there's a cycle, how does either car ever "get to the end, " since they continue around and around, and if there are a ton of nodes it might take a long while for the two to catch up.

punstress
Автор

There's place for optimization. If you are only checking that both are on the same location that could take considerable time. The optimal solution would be to check that fast was located before than slow's position on the previous iteration and in the current that fast is located ahead slow's position. Also, it should be mentioned if there's any paper or literature demonstrating that two nodes would eventually collide if moving in different speed in a linked list.

enicolasgomez
Автор

I started both fast and slow at head and did the increment before the comparison but its not passing all of the tests on leetcode, namely the last one that doesnt have a cycle

snakeb
Автор

Great explanation! I was thinking about the possibility of both pointers starting at the first node and swaping the if statement and the moving instructions locations so that slow moves before fast or fast moves before slow and then we check if they are equal. That way, them being at the start won’t affect the equality check.

wassimhaimoudi
Автор

What a great explanation! This instructor should consider writing a book or something!

nbjduin
Автор

Returning a boolean is easier than finding the beginning node of the loop. Eventually they'll collide and you'll return true, but on Cracking the Coding Interview, the same source code is used to return the beginning node of the circular loop and I can't wrap my head around it.

ItisLegit
Автор

GREAT video! SO illustrative and understandable! Glad I found this channel; hope to find more videos like this one! :)

MrGreeneyes
Автор

if there is a cycle, how would the pointers find out of they had reached the end of the list?

RandomMan
Автор

Nice explanation. If there is a loop, both pointers intersect. Thanks!

praveenjutur
Автор

Use Hash Table and store hash of node while iterating linked List and compare hash, if found in Hash Table then cycle exist

rohansheth
Автор

how do we know that the fast pointer should go back to the 4th node?

incaseyoumissedit
Автор

I'm just starting to learn coding, the question I have here, is where do you enter the length of the list? For instance if I have a linked list, something like this, x, y, z, a, b, c, d, e, f/  where do I run the code against my list?  Sorry for a noob question, just starting at this.

drgibblesgaming
Автор

Why not just use an array of pointers, and check that array each jump if the jump is already in the array?

SlykeThePhoxenix