← Back to course
Code Crew G3 / Week 07 / Thursday
4/6
Week 07 Β· Algorithms

Thursday

// Best way to solve it

Thursday: Maze Algorithms

Nova projects a maze on the floor. Rocket hurries through it. "I found a way out!" he says.

Raven counts his steps. "That works," she says. "Is there a shorter path?"

Nova says, "Interesting. Try a different route and count again." Rocket starts back at the beginning. Let's help them find a path, then a shorter one.

There is more than one way through a maze. Find a path from S to E. Then try to find a SHORTER path. Compare with a partner.

FIND A PATH

Find a path from S to E. Click cells in order to draw it. Walls block movement; you can't go diagonally.

S
Click S to start, then click each next cell. Path so far: 0 cells
WHY THIS EXERCISEThis is the idea behind path-finding: try each way, keep the shortest. CSTA 1B-AP-08.
First path (U/D/L/R):
Shorter path:
How many steps did you save?
Try Without Paper
Race a friend: who can put 5 cards in order fastest?
Compare your METHODS; that's comparing algorithms.

Pick Your Algorithm

For each problem, circle the BEST algorithm.

Find a friend in a sorted line of 30 kids: Linear / Binary
Find a candy in a messy backpack: Linear / Binary
Sort 4 socks by color: Bubble / Pick-Smallest

(There's no one right answer; defend your choice with a partner.)

Shortest Path Thinking

A path through a maze is an algorithm: a list of moves in order.

The shortest path uses the fewest moves. Count the moves to compare.

COMPARE THE PATHS
  • Read the question.
  • Tap your answer.
Path A takes 12 moves. Path B takes 9. Which is shorter?
A path goes R, R, L, R. Which two moves cancel out?
Take away those two moves. How many moves are left?
What helps a map app find the best route?
Moves: U, U, R, R, R. How many moves in all?
Write the R moves as a loop: REPEAT ___ TIMES: R. What number?
Path: R, D, R, D, R, D. How many D moves?
StatementTrue or false?
A maze can have more than one path.?
The shortest path always has the most turns.?
Comparing two paths is comparing two algorithms.?
A wall means you must find another way.?
WHY THIS EXERCISEPath finding is a famous algorithm problem in computer science.
Try it
Make a small maze on the floor with pillows or paper.
Find two different paths from start to end.
Count the steps for each. Which algorithm wins?
Safety first
Build the maze on a clear, flat floor.
Walk, do not run.
← Wednesday