From Zero to AI

Lesson 4.1: Algorithms in Everyday Life

Duration: 45 minutes

Learning Objectives

After completing this lesson, you will be able to:

  • Define what an algorithm is in simple terms
  • Identify algorithms in daily activities
  • Understand why algorithms are fundamental to programming
  • Recognize the characteristics of a good algorithm

Introduction

You already use algorithms every day without realizing it. When you follow a recipe, navigate to a friend's house, or decide what to wear based on the weather, you're executing algorithms. Understanding this connection between everyday problem-solving and programming is your first step toward thinking like a developer.

An algorithm is simply a set of step-by-step instructions to accomplish a specific task.


Main Content

What is an Algorithm?

The word "algorithm" might sound technical, but the concept is surprisingly simple:

┌─────────────────────────────────────────────────────────────┐
│                     ALGORITHM                                │
│                                                              │
│  A sequence of well-defined instructions that, when         │
│  followed, will always produce the same result for          │
│  the same input.                                            │
│                                                              │
│  INPUT[Step 1][Step 2][Step 3]  →  OUTPUT        │
└─────────────────────────────────────────────────────────────┘

Think of algorithms as reliable recipes. If you follow the same recipe with the same ingredients, you should get the same dish every time.

Algorithms You Already Know

Let's look at some algorithms you use regularly:

Morning Routine Algorithm

1. Wake up when alarm rings
2. Turn off alarm
3. Get out of bed
4. Go to bathroom
5. Brush teeth for 2 minutes
6. Take a shower
7. Get dressed
8. Eat breakfast
9. Leave for work/school

Making Tea Algorithm

1. Fill kettle with water
2. Turn on kettle
3. Wait until water boils
4. Put tea bag in cup
5. Pour hot water into cup
6. Wait 3-5 minutes
7. Remove tea bag
8. Add milk or sugar if desired
9. Enjoy tea

Crossing the Street Algorithm

1. Approach crosswalk
2. Look left
3. Look right
4. Look left again
5. If no cars are coming, cross the street
6. If cars are coming, wait and repeat from step 2

Notice how the last algorithm includes a decision point (if cars are coming) and potentially repeating steps. These are key elements we'll explore more in this module.

The Three Characteristics of a Good Algorithm

Not all sets of instructions qualify as good algorithms. Here's what makes an algorithm effective:

┌─────────────────────────────────────────────────────────────┐
│           CHARACTERISTICS OF A GOOD ALGORITHM                │
├─────────────────────────────────────────────────────────────┤
│                                                              │
│  1. CLEAR AND UNAMBIGUOUS                                   │
│     Every step must have one interpretation                 │
│     Bad:  "Add some flour"                                  │
│     Good: "Add 2 cups of flour"                             │
│                                                              │
│  2. FINITE                                                  │
│     Must eventually end                                     │
│     Bad:  "Keep stirring forever"                           │
│     Good: "Stir for 3 minutes"                              │
│                                                              │
│  3. EFFECTIVE                                               │
│     Each step must be doable                                │
│     Bad:  "Calculate the meaning of life"                   │
│     Good: "Calculate the total price"                       │
│                                                              │
└─────────────────────────────────────────────────────────────┘

Algorithms vs. Heuristics

It's important to distinguish algorithms from heuristics:

Algorithms Heuristics
Guaranteed to work Work most of the time
Same result every time Results may vary
Follow exact steps Use rules of thumb
Example: Long division Example: "Round to nearest 10"

When you're looking for a book in a library using the catalog system, you're using an algorithm. When you guess which aisle might have it based on experience, you're using a heuristic.

Computers primarily work with algorithms because they need certainty. They can't "guess" or "feel" their way to a solution.

From Real Life to Programming

Here's the exciting part: the same logical thinking you use for everyday tasks is exactly what programming requires.

Real Life: Make coffee every morning Programming: Automate a task that runs every morning

Real Life: Sort your bookshelf by author name Programming: Sort a list of names alphabetically

Real Life: Find the cheapest product in a store Programming: Find the minimum value in a list of prices

The syntax (the way you write code) will be new, but the logic underneath is something you already understand.

Visualizing Algorithms: Flowcharts

Programmers often use flowcharts to visualize algorithms before coding them. Here's how the "crossing the street" algorithm looks as a flowchart:

                    ┌─────────┐
                    │  START  │
                    └────┬────┘
                         │
                         ▼
              ┌──────────────────────┐
              │ Approach crosswalk   │
              └──────────┬───────────┘
                         │
                         ▼
              ┌──────────────────────┐
              │ Look left, right,    │
              │ left again           │
              └──────────┬───────────┘
                         │
                         ▼
                    ┌─────────┐
                   ╱           ╲     Yes
                  ╱  Cars       ╲──────────┐
                  ╲  coming?    ╱          │
                   ╲           ╱           │
                    └────┬────┘           │
                    No   │                │
                         ▼                │
              ┌──────────────────────┐    │
              │   Cross the street   │    │
              └──────────┬───────────┘    │
                         │                │
                         ▼                │
                    ┌─────────┐           │
                    │   END   │           │
                    └─────────┘           │
                         ▲                │
                         │     ┌──────────┘
                         │     │
              ┌──────────┴─────┴─────┐
              │        Wait          │
              └──────────────────────┘

The diamond shape represents a decision point. Depending on the answer, you follow different paths.

Why Algorithms Matter in Programming

Every piece of software is built from algorithms. When you:

  • Search on Google (uses search algorithms)
  • Get directions on Maps (uses pathfinding algorithms)
  • See recommendations on YouTube (uses recommendation algorithms)
  • Send a message on WhatsApp (uses encryption algorithms)

...you're using software built on the same fundamental concept: step-by-step instructions that produce predictable results.


Practice Exercise

Exercise 1: Identify the Algorithm

Which of the following is a proper algorithm? Explain why the others are not.

A) "Make something delicious for dinner" B) "Boil water: Fill pot with 2 liters of water, place on stove, turn heat to high, wait until bubbles appear" C) "Be creative" D) "Keep trying until you succeed" (with no other instructions)

Answer

B is the only proper algorithm because:

  • A is too vague (not unambiguous) — what is "delicious"?
  • B has clear, unambiguous steps with specific measurements
  • C is not actionable (not effective) — how do you "be creative"?
  • D might never end (not finite) and has no clear steps

Exercise 2: Write Your Own

Write an algorithm for one of these everyday tasks:

  1. Making a peanut butter and jelly sandwich
  2. Logging into your email
  3. Finding a specific book on a shelf
  4. Charging your phone

Your algorithm should have:

  • At least 6 steps
  • Clear, unambiguous instructions
  • A definite end

Exercise 3: Spot the Problem

This algorithm for "Getting ready for bed" has problems. Identify them:

1. Put on pajamas
2. Get into bed
3. Turn off the light
4. Fall asleep
Problems
  1. Missing steps: brush teeth, wash face, set alarm, etc.
  2. Step 4 "Fall asleep" is not actionable — you can't command yourself to sleep
  3. No mention of order issues — should turn off light before or after getting in bed?
  4. What if you're already wearing pajamas?

A better version might include conditions and more specific steps.


Key Takeaways

  • An algorithm is a sequence of clear, step-by-step instructions to solve a problem
  • You already use algorithms daily: recipes, directions, routines
  • Good algorithms are unambiguous, finite, and effective
  • Algorithms differ from heuristics — they guarantee results
  • Flowcharts help visualize algorithms before coding
  • All software is built from algorithms — learning to think algorithmically is essential for programming

Resources

Resource Type Difficulty
What is an Algorithm? - Khan Academy Video Beginner
Algorithms Explained - BBC Bitesize Tutorial Beginner
Everyday Algorithms - Medium Article Beginner