Welcome to Code Quest Island! What Are Algorithms Anyway?
The warm sand squishes between your toes as you walk along the shore, scanning the beach for cool shells and sea glass. Then you spot it: a crumpled, water-stained scroll half-buried under a pile of seaweed, tied with a frayed piece of red rope that looks suspiciously like a pirate’s bandana. You untie the rope and unroll the scroll, and a tiny, very sad face stares back at you, drawn in wobbly ink that’s smudged in a few spots from seawater. Next to the face is a note written in messy, all-caps handwriting: HELP! I’M BAZIL THE PIRATE. I LOST MY TREASURE MAP AND I CAN’T FIND MY HIDDEN GOLD TO BUY ICE CREAM FOR ALL THE KIDS ON THE ISLAND. IF YOU CAN HELP ME MAKE A NEW MAP, I’LL GIVE YOU A FREE PIRATE HAT AND A BAG OF CANDY.
You look up and see a pirate running toward you, his tri-corner hat askew, his curly brown beard full of sand, and his left foot bare (he lost his shoe running across the beach). He skids to a stop in front of you, holding an empty piece of parchment and a half-used piece of chalk. “I’m so glad you found my scroll!” he says, sniffling a little. “I had a perfect map last week, but a big wind blew it into the ocean. I tried to draw a new one, but every time I follow my own instructions, I either dig up a crab nest and get pinched on the nose, or find a old soda can, or walk straight into the ocean. I don’t know what I’m doing wrong!”
You take the parchment from him and look at the wobbly lines he’s drawn. At the top, he’s written: FIND TREASURE INSTRUCTIONS. The first line says: GO TO THE PLACE WITH LOTS OF TREES. The second line says: DIG SOMEWHERE SHINY. You frown. That’s… not very helpful. There are hundreds of trees on the island, and lots of shiny things (like soda cans, sea glass, and even pirate coins that other pirates lost) scattered everywhere.
“See?” Bazil says, kicking at a rock. “I follow those steps and I never find the treasure. What’s wrong?”
You think for a second. You’ve never made a treasure map before, but you’ve done lots of other things that have step-by-step rules. Like making a peanut butter and jelly sandwich. Or packing your backpack for school. Or beating the hardest level of your favorite video game. You don’t even have to think about those steps most of the time—you just do them, and they work every time.
“I think I know how to help,” you say. “We just need to make better instructions. Instructions that don’t have any fuzzy words, and tell you exactly what to do, step by step, in order. Those kinds of instructions have a fancy name: they’re called algorithms.”
Bazil’s eyes go wide. “Al-go-rithms? That sounds like a magic spell!”
You laugh. “Not magic! Just a fancy word for a plan that tells you how to solve a problem, step by step, so you get the right answer every time. And the best part? You already use algorithms every single day, even when you’re not looking for treasure.”
Bazil’s jaw drops. “I do? But I’m just a pirate! I don’t know anything about fancy words!”
“Of course you do!” you say. “Let’s prove it. What’s the first thing you do when you wake up in the morning on your pirate ship?”
Bazil scratches his head. “Uh… I wake up, then I put on my hat, then I eat a banana for breakfast, then I feed my pet parrot, then I clean the deck.”
“Exactly!” you say. “That’s an algorithm! It’s a step-by-step plan for getting your morning done. If you skipped a step, like feeding your parrot, he’d squawk at you all day. If you did the steps in the wrong order, like eating your banana before you put on your hat, you might get banana on your hat, and that’s a mess.”
Bazil grins. “Oh! So that’s what an algorithm is? I thought it was something only computer people know about!”
“Nope!” you say. “Everyone uses algorithms, all the time. Let’s do another one. What do you do when you want to make a peanut butter and jelly sandwich?”
Bazil thinks for a second. “I get two pieces of bread, then I get the peanut butter jar, then I get the jelly jar, then I spread peanut butter on one piece, then jelly on the other, then I put them together, then I cut them in half.”
“Perfect! That’s another algorithm. And if you did the steps wrong—like spreading jelly first, then peanut butter, then forgetting to put the bread together—you wouldn’t get a sandwich. You’d get a mess.”
<!-- [Paper Book Illustration 1: Bazil the pirate holding a piece of bread with peanut butter and jelly smudged on it, looking confused, while a kid points at a list of sandwich steps next to him] --> <!-- [Digital Edition Sidebar: Try It Yourself!] Write down the 3 steps you follow when you brush your teeth before bed. That’s your very own tooth-brushing algorithm! -->
Now you’re excited. You can help Bazil make a treasure-finding algorithm, and you already know how to do it. But first, you need to make sure the steps are super clear, with no fuzzy words. “The problem with your old instructions is that they’re too vague,” you explain to Bazil. “‘Go to the place with lots of trees’ is bad because there are lots of tree places. ‘Dig somewhere shiny’ is bad because there are lots of shiny things. We need to make each step so clear that even a pirate who just woke up could follow it.”
Bazil nods so hard his hat falls over his eyes. “Okay! Let’s do it! What’s first?”
You grab the chalk and think. The last time Bazil saw the treasure, he was standing on the beach, right? “First step: Stand on the beach, facing the ocean. Face exactly east, where the sun comes up in the morning. Got it?”
Bazil repeats it back to you, writing it down carefully. “Step 1: Stand on the beach, facing east. Yes!”
“Great. Second step: Walk exactly 10 steps forward, counting each step out loud. Don’t turn, don’t stop, just walk 10 steps.”
Bazil writes that down too, his tongue sticking out of his mouth as he concentrates. “Step 2: Walk 10 steps forward, counting. Got it.”
“Third step: Turn left 90 degrees, so you’re facing north now. Walk forward until you see the tallest coconut tree on the beach. Stop right at the base of the tree.”
“Step 3: Turn left, walk to the tallest coconut tree. Perfect!”
“Fourth step: Take the small shovel you keep in your pirate belt, and dig exactly 3 feet straight down. Stop when you hit something hard that isn’t a root or a rock.”
Bazil’s eyes light up. “Step 4: Dig 3 feet down! That’s it? That’s so easy!”
“Yep! That’s an algorithm,” you say. “It has four steps, each one is clear, no fuzzy words, and if you follow them exactly, you’ll find the treasure. Let’s test it! You do the steps, and I’ll watch.”
Bazil scrambles to follow the instructions. He stands facing east, counts 10 steps, turns left, walks to the tallest coconut tree, and starts digging. Three feet down, his shovel hits something with a loud *clank*. He whoops and digs faster, pulling out a rusty old chest covered in barnacles. He pops it open, and it’s full of gold coins, shiny jewels, and a giant bag of sour candy. “WE FOUND IT!” he screams, dancing around. “YOU’RE A GENIUS! HERE’S YOUR PIRATE HAT AND CANDY, JUST LIKE I PROMISED!”
You laugh as he shoves a sparkly plastic pirate hat on your head and a bag of sour gummy worms in your hand. “See? That’s the power of a good algorithm. If your instructions are clear and step-by-step, you can solve any problem—even finding hidden treasure.”
But Bazil’s smile fades a little. “Wait, what if I have to find more treasure later? Do I have to write a whole new algorithm every time? That sounds like a lot of work.”
You shake your head. “Nope! You can reuse algorithms for similar problems. For example, if you want to find another treasure that’s hidden near a palm tree instead of a coconut tree, you can just change step 3 from ‘tallest coconut tree’ to ‘tallest palm tree’, and keep the rest of the steps the same. That’s one of the best things about algorithms: they’re reusable.”
Bazil’s face lights up again. “Oh! That’s even better! So I can make one algorithm for finding treasure near trees, one for finding treasure near rocks,