Understanding Algorithms Through Tea
YouTube Video
🎯 Lesson Objectives
By the end of this lesson, you will:
- Understand what an algorithm is
- Practice breaking complex tasks into simple steps
- Experience how computers "think"
- Compare your algorithm to an AI-generated one
📖 What is an Algorithm?
Algorithm Defined
An algorithm is simply a step-by-step set of instructions to accomplish a task.
You create and follow algorithms every day without realizing it:
| Everyday Algorithm | What You're Really Doing |
|---|---|
| Your morning routine | A sequence of steps you follow automatically |
| A recipe | Instructions to transform ingredients into food |
| Directions to a location | Steps to get from point A to point B |
| Your workout routine | A planned sequence of exercises |
Algorithms are the foundation of all software. Every app, website, and program is just a collection of algorithms working together.
🤖 Why This Matters for Vibe Coding
When you vibe code, you're essentially:
- Thinking of an algorithm (the logic)
- Describing it to AI
- AI translates it into working code
The better you are at creating clear, complete algorithms, the better your AI-generated code will be.
The Algorithm Skill
Vague Thinking → Vague Prompt → Broken Code
Clear Algorithm → Clear Prompt → Working Code
🍵 The Challenge: Making Tea
Your task is to write an algorithm for making tea that a robot could follow.
Why a Robot?
Imagine you're programming a robot that:
- Has never seen tea before
- Doesn't know what "hot" means until you define it
- Will do EXACTLY what you say (nothing more, nothing less)
- Will stop and crash if it encounters something unexpected
This is how computers work. They need explicit, precise instructions.
📜 The Rules
Algorithm Rules
-
Each step must be a single, simple action
- ❌ "Make the tea" (too vague)
- ✅ "Pour hot water into the cup"
-
Assume the robot knows nothing
- ❌ "Boil water" (robot doesn't know how)
- ✅ "Turn kettle power switch to ON position"
-
Include decision points
- What if there's no water in the kettle?
- What if the user wants milk? What if they don't?
-
Handle errors
- What if something goes wrong?
- When should the robot stop?
✍️ Part 1: Your Algorithm (15 minutes)
Get out a piece of paper or open a notes app. Write your tea-making algorithm.
Starting point:
Algorithm: Making Tea
Prerequisites: Kitchen with kettle, tea bags, cups, water source
Step 1: _______________
Step 2: _______________
Step 3: _______________
...
📝 Example Algorithm
After you've written yours, compare it to this example:
1Algorithm: Making Tea2 3SETUP:4Step 1: Locate the kitchen area5Step 2: Check if electric kettle is present6 IF no kettle: STOP and report "No kettle available"7Step 3: Check if kettle is plugged into electrical outlet8 IF not plugged in: Insert plug into outlet9Step 4: Check if kettle has water10 IF no water: Go to Step 511 IF has water: Go to Step 812 13FILL KETTLE:14Step 5: Remove kettle from base15Step 6: Take kettle to water source (sink/tap)16Step 7: Fill kettle with water to minimum line (at least 500ml)17Step 8: Place kettle on base18 19HEAT WATER:20Step 9: Press power button to ON21Step 10: Wait until kettle clicks off (water boiled)22 IF kettle doesn't click after 5 minutes: STOP and report "Kettle malfunction"23 24PREPARE CUP:25Step 11: Get a clean cup from cupboard26Step 12: Check cup is clean and not cracked27 IF cracked: Get different cup28Step 13: Place cup on counter near kettle29Step 14: Get one tea bag from tea container30Step 15: Place tea bag in cup31 32POUR AND STEEP:33Step 16: Lift kettle from base34Step 17: Carefully pour hot water into cup (fill to 80% capacity)35Step 18: Place kettle back on base36Step 19: Wait 3-5 minutes for tea to steep37 38FINISH:39Step 20: Remove tea bag from cup40Step 21: Dispose of tea bag in bin41Step 22: Ask user: "Would you like milk?"42 IF yes: Go to Step 2343 IF no: Go to Step 2544Step 23: Get milk from refrigerator45Step 24: Pour small amount of milk into tea (approximately 20ml)46Step 25: Ask user: "Would you like sugar?"47 IF yes: Go to Step 2648 IF no: Go to Step 2849Step 26: Get sugar container50Step 27: Add one teaspoon of sugar to tea51Step 28: Stir tea with spoon for 5 seconds52Step 29: Present tea to user53Step 30: END54 55ERROR HANDLING:56- If any item is not found: STOP and report what is missing57- If water spills: STOP and report "Spill detected, cleaning required"58- If user has additional requests: Return to appropriate stepThat's 30+ steps for making tea!
🔍 Part 2: Analyze Your Algorithm
✅ Check Your Algorithm
0/6Question 1: How many steps did you have?
- Less than 10? You probably missed a lot of detail
- 10-20? Good start, but likely some gaps
- 20-30+? Excellent attention to detail!
Question 2: What did you assume?
Common assumptions people make:
- The kettle would be where expected
- There would be water available
- The user can pour water safely
- The cup is clean
- Electricity is working
🤖 Part 3: AI Comparison
Now let's see how AI writes this algorithm!
💡 Tips:
- • Copy this prompt to ChatGPT or Claude
- • Compare AI's version to yours
- • Note what AI includes that you might have missed
After getting AI's response, answer these questions:
✅ AI Comparison
0/4💡 Key Insights
What You Learned
-
Computers Need Explicit Instructions What seems obvious to us ("make tea") requires many specific steps for a computer.
-
Assumptions Break Algorithms Every assumption is a potential bug. Good algorithms anticipate problems.
-
Decision Points Create Flexibility The IF/THEN structure lets one algorithm handle many scenarios.
-
AI Is Good at Detail — But Not Perfect AI often generates comprehensive algorithms, but may miss context-specific details you would know.
-
Your Brain Already Works This Way You process these algorithms unconsciously. Programming just makes them explicit.
🧪 Extension Challenges
Want more practice? Try these:
| Difficulty | Challenge | Hint |
|---|---|---|
| Easy | Brushing Your Teeth | Consider: paste amount, brush duration, rinsing |
| Medium | Crossing a Busy Street | Consider: checking for signals, looking both ways, timing |
| Hard | Making Friends at a New School | Consider: identifying potential friends, starting conversations, handling rejection |
Notice: The harder the task, the more decisions and conditions needed!
✅ Lesson Summary
The Skill You Practiced
Decomposition — Breaking complex tasks into simple, sequential steps.
This is the CORE skill of programming and vibe coding.