Understanding Algorithms in 5 Levels of Difficulty
Introduction
Algorithms are everywhere. They’re not just abstract computer science concepts confined to textbooks and university lectures—they’re fundamental to how we navigate daily life, from following a morning routine to scrolling through social media. Professor David J. Malan of Harvard University guides us through five levels of understanding algorithms, each building on the last, revealing how these step-by-step instructions power everything from making sandwiches to training artificial intelligence.
Level 1: The Child – Algorithms as Instructions
What is a Computer?
Before diving into algorithms, it’s worth understanding what a computer actually is. As one young student explains, a computer is “electronic like a phone, but it’s a rectangle and you can type like tick tick tick and you work on it.”
Inside every computer are critical components:
- CPU (Central Processing Unit): The brain of the computer that responds to instructions like moving up, down, left, or right, and performs mathematical operations like addition and subtraction.
- Memory (RAM): Random Access Memory where your games and programs are stored while being used.
- Storage (Hard Drive/SSD): Where your data stays permanently—your high scores, documents, and essays remain even when the power goes out.
Making a Peanut Butter Sandwich: Algorithm in Action
The simplest way to understand an algorithm is through a familiar task: making a peanut butter sandwich. An algorithm is simply a list of step-by-step instructions for solving a problem or completing a task.
When asked to instruct “a robot” (the professor) to make a sandwich, the young student learns a crucial lesson about precision:
- “Open the bag”
- “Grab the bread and put it on the plate”
- “Take the lid off the peanut butter”
- “Take the knife”
- “Put the blade inside the peanut butter and spread the peanut butter on the bread”
- “Put the knife down”
- “Grab one bread and put it on top of the second bread”
The exercise reveals a fundamental truth: precision matters. When the student initially said “grab the bread,” without specifying “one slice,” the professor took out all the bread—exactly following the instruction given. This demonstrates why being very correct with instructions is crucial in programming.
Algorithms in Everyday Life
The bedtime routine is an algorithm:
- Get dressed
- Brush teeth
- Read a story
- Go to bed
Even something as simple as searching on Google requires precise instructions. Type in just “Google” and you won’t find the answer to your question. Algorithms require specificity to work correctly.
Level 2: The Teenager – Searching and Efficiency
The Phone Book Problem
Before smartphones, everyone’s phone numbers were printed in massive phone books—thousands of pages of alphabetically organized names and numbers. This presents a perfect problem for understanding different algorithmic approaches.
How do you find “John” in a 1,000-page phone book?
Algorithm 1: Linear Search
The simplest approach: start at the beginning and look at each page, one by one, searching for John. This works, but could take up to 1,000 steps in the worst case (if John is at the end or not in the book).
In programming, this uses a loop—doing something again and again.
Algorithm 2: Faster Linear Search
Go two pages at a time instead of one. This is twice as fast (500 steps maximum), but there’s a problem: you might skip right over John if he’s on one of the pages you jumped past.
The solution? When you get close (say, you reach the K section), either:
- Switch to going one page at a time, or
- Double back one page to check
This algorithm is faster but requires an extra correction step to remain accurate.
Algorithm 3: Binary Search (Divide and Conquer)
The smartest approach:
- Open to the middle of the book (roughly the K section)
- Ask: Is John to the left or right?
- Tear the problem in half—throw away the half that doesn’t contain John
- Repeat with the remaining half
How many steps does this take?
Starting with 1,000 pages:
- After step 1: 500 pages
- After step 2: 250 pages
- After step 3: 125 pages
- After step 4: 63 pages
- After step 5: 32 pages
- After step 6: 16 pages
- After step 7: 8 pages
- After step 8: 4 pages
- After step 9: 2 pages
- After step 10: 1 page
Approximately 10 steps versus 1,000!
This is fundamentally faster because you’re dividing and conquering—cutting the problem in half each time rather than just taking small bites. This is exactly how your smartphone searches through your contacts.
Recursive Algorithms
Binary search demonstrates a recursive algorithm—an algorithm that uses itself to solve the same problem again and again, but on progressively smaller pieces.
Level 3: The College Student – Sorting and Complexity
The Sorting Problem
Patricia, a computer science student at NYU, tackles a fundamental challenge: sorting numbers from smallest to largest. There are many ways to sort, each with different efficiencies.
Bubble Sort: Fixing Local Problems
Bubble sort focuses on small, local problems rather than trying to fix everything at once.
The Algorithm:
- Compare the first two numbers
- If they’re out of order, swap them
- Move to the next pair and repeat
- Continue until you reach the end
- Repeat the entire process until no swaps are needed
Example with numbers: 8, 1, 2, 6, 3, 4, 7, 5
The Role of Machine Learning
These recommendation systems aren’t simply programmed with rules like “if Patricia likes X, show her Y.” That would require infinitely long code for billions of users and pieces of content.
Instead, they use machine learning—algorithms that learn patterns from data:
- Input: What users watch, click on, and engage with
- Process: Neural networks and machine learning models find patterns
- Output: Predictions about what to show each user next
This represents a shift from explicitly programmed instructions to systems that infer behavior from data.
Level 4: The PhD Researcher – Learning and Optimization
The Evolution of AI Algorithms
Anish, a fourth-year PhD student researching robot learning at NYU, explains how algorithms have evolved from simple rule-based systems to sophisticated learning agents.
Classical AI: Search-Based Gameplay
Traditional game-playing algorithms like A search* work through pure computation:
- Observe the current game state
- Search through all possible next moves
- Evaluate which moves lead to the best outcomes
- Pick the optimal move
These algorithms don’t “learn”—they calculate. Every time they play, they start fresh with the same strategy.
Modern AI: Learning Algorithms
Systems like AlphaGo and AlphaZero represent a different paradigm:
- They play thousands or millions of games
- They refine their strategies based on what works
- They get progressively better with more data
- They adapt to new situations they’ve never explicitly seen
The Key Difference: The high-level abstraction is the same (see data, learn from it), but the objective function matters:
- Is the goal to win the game?
- Force a tie?
- Open a door?
- Navigate a room?
The Objective Function
In machine learning, the objective function defines what “success” means. Algorithms optimize toward this goal, which means:
- Careful design is critical: If you optimize for engagement, you might create addictive products
- Unintended consequences emerge: Optimizing for clicks might prioritize sensationalism
- Ethics matter: What we choose to optimize shapes the world
Algorithms in Daily Life
Algorithms are becoming ubiquitous, often invisibly:
- Transit systems: Routes optimized for 50+ years
- Smartphone notifications: Timed using engagement algorithms
- Financial systems: High-frequency trading algorithms
- Healthcare: Diagnostic assistance and treatment recommendations
The Double-Edged Sword
While algorithms improve efficiency and convenience, they also:
- Mine personal data constantly
- Influence what we see and believe
- Sometimes treat people as “just a pair of eyes with a wallet”
- Create filter bubbles and echo chambers
The challenge is harnessing algorithmic power to genuinely improve lives without reducing human beings to data points.
Level 5: The Expert – Theory, Practice, and the Future
Data Science and Algorithm Deployment
Professor Chris Wiggins, Associate Professor of Applied Mathematics at Columbia and Chief Data Scientist at The New York Times, bridges academic theory and real-world application.
Algorithms in Two Worlds
Academia: Algorithms focus on optimization—finding the best model or description of a dataset through mathematical rigor.
Industry: Algorithms become data products that must:
- Integrate with existing systems
- Handle reliable input and produce useful output
- Work within organizational workflows
- Serve actual business or user needs
The AI Explosion and Large Language Models
When most people say “AI” today, they think of:
- Large Language Models (LLMs): Systems trained on vast text corpora
- Generative AI: Creating new content (text, images, video)
- Chatbots: Conversational interfaces like ChatGPT
Important hierarchy:
- Chatbot is a special case of…
- Generative AI, which is a special case of…
- Large Language Models, which is a special case of…
- Machine Learning generally, which is…
- What most people mean by “AI”
The Alchemy Phase
Current large language model development is described as “alchemy”:
- Designers try different architectures without clear a priori knowledge
- Large companies experiment extensively
- What works gets published and productized
- The scientific understanding follows engineering success
The Mystery: We still don’t fully understand why deep neural networks work so well. These are billion-parameter models that learn remarkably effectively, but interpreting how they do what they do remains challenging.
Is Understanding Required?
This raises a philosophical question: Do we need to understand exactly how an algorithm works to use it effectively?
Historical Precedent: Science has many examples where:
- An algorithm or model works excellently
- Our understanding of why is limited or incomplete
- Sometimes published proofs turn out to be wrong
- The algorithm continues working well anyway
The Car Analogy: You don’t need to understand organic chemistry to drive a car, even though combustion powers the engine. Similarly:
- You can import scikit-learn and do machine learning in seconds
- You don’t need to understand the underlying optimization algorithms
- Different levels of the “stack” require different knowledge
- Understanding deeper can help, but isn’t always necessary for progress
Conclusion: Algorithms as a Journey
From making peanut butter sandwiches to training neural networks, algorithms represent step-by-step solutions to problems. They exist at every level of complexity, from explicit instructions a child can follow to sophisticated learning systems that even their creators don’t fully understand.
Key Takeaways:
- Algorithms are everywhere: From morning routines to social media feeds, step-by-step instructions govern much of modern life.
- Efficiency matters: The difference between checking 1,000 pages and 10 pages is the difference between algorithms that work and algorithms that excel.
- Precision is critical: Computers follow instructions exactly—ambiguity leads to unexpected results.
- Learning algorithms are different: Modern AI doesn’t just follow rules; it infers patterns from data.
- Understanding has levels: You can work with algorithms at many levels of abstraction, from using tools to inventing new approaches.
- The field keeps evolving: What seems cutting-edge today becomes foundational tomorrow.
- Ethics matter: As algorithms increasingly shape society, understanding their impacts—intended and unintended—becomes crucial.
Whether you’re teaching a child to make a sandwich or researching the next breakthrough in artificial intelligence, you’re working with algorithms. The journey from one level to the next is continuous, accessible, and increasingly important in our algorithmic world.
The future belongs not just to those who use algorithms, but to those who understand them well enough to shape how they’re deployed—ensuring they serve humanity rather than merely optimizing metrics. As Professor Malan reminds us, each lesson learned, each algorithm studied, brings that advanced frontier closer within reach.
About This Article: This comprehensive exploration of algorithms is based on an educational video featuring Professor David J. Malan of Harvard University, explaining algorithms across five levels of expertise. The conversation illustrates how fundamental concepts scale from intuitive everyday examples to cutting-edge artificial intelligence research.