Floyd's Tortoise and Hare

preview_player
Показать описание
In this video, I introduce an interesting algorithm to solve cycle detection problems.

Download the file used in this video here:

00:00 • Introduction

00:45 • Middle of a Linked List

02:15 • Duplicate Numbers

10:00 • Happy Numbers

Music by (Prod. Riddiman):
Рекомендации по теме
Комментарии
Автор

You are a genius! Spent a whole day trying to understand why moving tortoise to the beginning and moving both at the same speed would get to the beginning of the cycle.
Finally understood after watching your explanation! Nobody on the internet explains it as intuitively as you do.

raihankg
Автор

I'm still a bit confused about why we need to push the hare one step forward from the collision point when moving tortoise to the beginning.

raihankg
Автор

Hey everyone!!

I have included a written explanation for each algorithm if you don't want to listen to my voice!!!

Bonus problem: detect a palindrome in a linked list using floyds algorithms. Hint: use a stack and find the middle of the list.

FI.

formulaint
Автор

How can one determine whether a singly linked list has a cycle?

saadokiller