How to solve any maze

Veritasium · Intermediate ·📐 ML Fundamentals ·10mo ago
Skills: ML Pipelines70%

Key Takeaways

The video demonstrates the flood fill algorithm, depth-first search, and breadth-first search to solve mazes, highlighting their strengths and weaknesses in finding the shortest path.

Full Transcript

You can solve a maze with your eyes closed. If you just put one hand along one wall, you will eventually reach the end of most common mazes. After a simple wall following mouse took home gold in the first finals, the goal of the maze was moved away from the edges and freestanding walls were added. Your next instinct might be to run through the maze, taking note of every fork in the road. Whenever you reach a dead end or a loop, you can go back to the last intersection and try a different path. If your last left turn got you nowhere, you'd come back to that intersection and go right instead. You can think of this strategy as the one a headstrong mouse might use, running as deep into the maze as it can and turning back only when it can't go any further. This search strategy known as depth first search will eventually get the mouse to the goal. The problem is it might not be the shortest route. The sibling to this search algorithm, breadth first search, would find the shortest path. With this strategy, the mouse runs down one branch of an intersection until it reaches the next one. Then it goes back to check the path it skipped before moving on to the next layer of intersections. So the mouse checks every option it reaches. But all that backtracking means that it's rerunning paths dozens of times. At this point, even searching the whole maze often takes less time. So why not just do that? A meticulous mouse could search all 256 cells of the maze, testing every turn and corner to ensure it has definitely found the shortest path. But searching so thoroughly isn't necessary either. Instead, the most popular micro mouse strategy is different from all of these techniques. It's a search algorithm known as flood fill. This mouse's plan is to make optimistic journeys through the maze. They simply draw the shortest path to the goal and go. When their optimistic plan inevitably hits a wall that wasn't on their map, they simply mark it down and update their new shortest path to the goal. Under the hood of the algorithm, what the micro mouse is marking on their map is the distance from every square in the maze to the goal. To travel optimistically, the mouse follows the trail of decreasing numbers down to zero. Whenever they hit a wall, they update the numbers on their map to reflect the new shortest distance to the goal. This strategy of following the numerical path of least resistance gives the floodfill algorithm its name. The process resembles flooding the maze with water and updating values based on the flow. While this algorithm isn't guaranteed to find the best path on first pass, it takes advantage of the fact that micro mice need to return to the start to begin their next run. So if the mouse treats its return as a new journey, it can use the return trip to search the maze as well. Between these two attempts, both optimized to find the shortest path from start to finish, it's extremely likely that the mouse will discover it. And the mouse will have done it efficiently, often leaving irrelevant areas of the maze entirely untouched.

Original Description

By following this algorithm you can solve any maze in the world.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Veritasium · Veritasium · 0 of 60

← Previous Next →
1 Scientific Notation - Explained!
Scientific Notation - Explained!
Veritasium
2 I'm Atoms (Scientific Cover of Jason Mraz's I'm Yours)
I'm Atoms (Scientific Cover of Jason Mraz's I'm Yours)
Veritasium
3 Scientific Notation - Example
Scientific Notation - Example
Veritasium
4 What is a Force?
What is a Force?
Veritasium
5 Khan Academy and the Effectiveness of Science Videos
Khan Academy and the Effectiveness of Science Videos
Veritasium
6 Supercooled Water - Explained!
Supercooled Water - Explained!
Veritasium
7 Galileo the Scientific Parrot
Galileo the Scientific Parrot
Veritasium
8 Radiation vs Radioactive Atoms
Radiation vs Radioactive Atoms
Veritasium
9 What Is Electricity? (Are You Gonna Be My Girl?)
What Is Electricity? (Are You Gonna Be My Girl?)
Veritasium
10 Why Is Ice Slippery?
Why Is Ice Slippery?
Veritasium
11 Impress Her With Nanodiamonds
Impress Her With Nanodiamonds
Veritasium
12 Chain Drop Experiment
Chain Drop Experiment
Veritasium
13 What Colour Is Most Attractive?
What Colour Is Most Attractive?
Veritasium
14 States of Matter
States of Matter
Veritasium
15 Slinky Drop Answer
Slinky Drop Answer
Veritasium
16 Slinky Drop
Slinky Drop
Veritasium
17 Atomic Rant
Atomic Rant
Veritasium
18 What Is The Magnus Force?
What Is The Magnus Force?
Veritasium
19 A Human Being Is A Part Of The Whole
A Human Being Is A Part Of The Whole
Veritasium
20 Spinning Tube Trick Explained
Spinning Tube Trick Explained
Veritasium
21 Where Do Trees Get Their Mass?
Where Do Trees Get Their Mass?
Veritasium
22 Why Do You Make People Look Stupid?
Why Do You Make People Look Stupid?
Veritasium
23 Gyroscopic Precession
Gyroscopic Precession
Veritasium
24 How Does A Slinky Fall?
How Does A Slinky Fall?
Veritasium
25 Spinning Disk Trick Solution
Spinning Disk Trick Solution
Veritasium
26 Does a Falling Slinky Defy Gravity?
Does a Falling Slinky Defy Gravity?
Veritasium
27 Northern Lights From 100,000 ft!
Northern Lights From 100,000 ft!
Veritasium
28 The First Meeting of EDUtubers! ft. CGPGrey, Vsauce, Smarter Every Day, Numberphile +more
The First Meeting of EDUtubers! ft. CGPGrey, Vsauce, Smarter Every Day, Numberphile +more
Veritasium
29 Free Higgs!
Free Higgs!
Veritasium
30 How Can Trees Be Taller Than 10m?
How Can Trees Be Taller Than 10m?
Veritasium
31 What Now For The Higgs Boson?
What Now For The Higgs Boson?
Veritasium
32 How Trees Bend the Laws of Physics
How Trees Bend the Laws of Physics
Veritasium
33 Paralysed Rats Made To Walk Again
Paralysed Rats Made To Walk Again
Veritasium
34 What Could Survive An Atomic Bomb?
What Could Survive An Atomic Bomb?
Veritasium
35 Heisenberg's Uncertainty Principle Explained
Heisenberg's Uncertainty Principle Explained
Veritasium
36 Why Do Venomous Animals Live In Warm Climates?
Why Do Venomous Animals Live In Warm Climates?
Veritasium
37 Veritasium Trailer
Veritasium Trailer
Veritasium
38 What Can Frogs See That We Can't?
What Can Frogs See That We Can't?
Veritasium
39 World's Roundest Object!
World's Roundest Object!
Veritasium
40 Epic Slow-Mo Drum Implosions!
Epic Slow-Mo Drum Implosions!
Veritasium
41 Empty Space is NOT Empty
Empty Space is NOT Empty
Veritasium
42 Your Mass is NOT From the Higgs Boson
Your Mass is NOT From the Higgs Boson
Veritasium
43 How Does a Transistor Work?
How Does a Transistor Work?
Veritasium
44 Bullet Block Explained!
Bullet Block Explained!
Veritasium
45 How We’re Fooled By Statistics
How We’re Fooled By Statistics
Veritasium
46 Facebook Fraud
Facebook Fraud
Veritasium
47 The Most Common Cognitive Bias
The Most Common Cognitive Bias
Veritasium
48 Anti-Gravity Wheel?
Anti-Gravity Wheel?
Veritasium
49 Anti-Gravity Wheel Explained
Anti-Gravity Wheel Explained
Veritasium
50 Why Trees Are Taller Than They Need To Be
Why Trees Are Taller Than They Need To Be
Veritasium
51 Misconceptions About the Universe
Misconceptions About the Universe
Veritasium
52 Why Women Are Stripey
Why Women Are Stripey
Veritasium
53 What is NOT Random?
What is NOT Random?
Veritasium
54 Explained: 5 Fun Physics Phenomena
Explained: 5 Fun Physics Phenomena
Veritasium
55 Climate Change is Boring
Climate Change is Boring
Veritasium
56 13 Misconceptions About Global Warming
13 Misconceptions About Global Warming
Veritasium
57 CapitolTV's DISTRICT VOICES - District 5: Electric Sparks From Falling Water
CapitolTV's DISTRICT VOICES - District 5: Electric Sparks From Falling Water
Veritasium
58 Sparks from Falling Water: Kelvin's Thunderstorm
Sparks from Falling Water: Kelvin's Thunderstorm
Veritasium
59 The Most Persistent Myth
The Most Persistent Myth
Veritasium
60 The Most Radioactive Places on Earth
The Most Radioactive Places on Earth
Veritasium

The video teaches how to solve mazes using different search algorithms, including flood fill, depth-first search, and breadth-first search, and explains their advantages and disadvantages in finding the shortest path. By understanding these algorithms, viewers can develop problem-solving skills and apply them to various complex problems. The flood fill algorithm is a particularly efficient method that takes advantage of the mouse's return trip to search the maze and find the shortest path.

Key Takeaways
  1. Choose a search algorithm
  2. Implement the algorithm
  3. Test and optimize the algorithm
  4. Apply the algorithm to solve the maze
  5. Update the algorithm based on new information
  6. Repeat the process until the shortest path is found
💡 The flood fill algorithm's ability to update its numerical path based on new information and take advantage of the return trip makes it an efficient method for solving mazes.

Related Reads

📰
Programming Assignments: A Complete Guide to Solving Coding Problems Faster and Smarter
Learn to solve coding problems faster and smarter with a complete guide to programming assignments
Medium · Programming
📰
Design and Validation of a Lightweight 1D CNN for Affective Touch Classification in Soft Plush Companions
Learn to design and validate a lightweight 1D CNN for affective touch classification in soft plush companions, enabling socially assistive technologies to interpret human emotions through touch
ArXiv cs.AI
📰
How I Auto-Groomed 500 Jira Tickets with ML and LLM
Learn how to auto-groom Jira tickets using ML and LLM, increasing productivity and efficiency in project management
Medium · Machine Learning
📰
Day 161 of Learning Java & DSA: Solving the Largest Rectangle in a Histogram Using Stack
Learn to solve the Largest Rectangle in a Histogram problem using a stack-based approach in Java
Medium · Programming
Up next
SQLite3 Tutorial - Learn SQL for Python in 17 Minutes
Thomas Janssen
Watch →