AI EducademyAIEducademy
๐ŸŒณ

AI Foundations

๐ŸŒฑ
AI Seeds

Start from zero

๐ŸŒฟ
AI Sprouts

Build foundations

๐ŸŒณ
AI Branches

Apply in practice

๐Ÿ•๏ธ
AI Canopy

Go deep

๐ŸŒฒ
AI Forest

Master AI

๐Ÿ”จ

AI Mastery

โœ๏ธ
AI Sketch

Start from zero

๐Ÿชจ
AI Chisel

Build foundations

โš’๏ธ
AI Craft

Apply in practice

๐Ÿ’Ž
AI Polish

Go deep

๐Ÿ†
AI Masterpiece

Master AI

๐Ÿš€

Career Ready

๐Ÿš€
Interview Launchpad

Start your journey

๐ŸŒŸ
Behavioral Mastery

Master soft skills

๐Ÿ’ป
Technical Interviews

Ace the coding round

๐Ÿค–
AI & ML Interviews

ML interview mastery

๐Ÿ†
Offer & Beyond

Land the best offer

View All Programsโ†’

Lab

7 experiments loaded
๐Ÿง Neural Network Playground๐Ÿค–AI or Human?๐Ÿ’ฌPrompt Lab๐ŸŽจImage Generator๐Ÿ˜ŠSentiment Analyzer๐Ÿ’กChatbot Builderโš–๏ธEthics Simulator
๐ŸŽฏMock InterviewEnter the Labโ†’
JourneyBlog
๐ŸŽฏ
About

Making AI education accessible to everyone, everywhere

โ“
FAQ

Common questions answered

โœ‰๏ธ
Contact

Get in touch with us

โญ
Open Source

Built in public on GitHub

Get Started
AI EducademyAIEducademy

MIT Licence. Open Source

Learn

  • Academics
  • Lessons
  • Lab

Community

  • GitHub
  • Contribute
  • Code of Conduct
  • About
  • FAQ

Support

  • Buy Me a Coffee โ˜•
  • Terms of Service
  • Privacy Policy
  • Contact
AI & Engineering Academicsโ€บ๐ŸŒฟ AI Sproutsโ€บLessonsโ€บAlgorithms Explained
๐Ÿ“
AI Sprouts โ€ข Beginnerโฑ๏ธ 15 min read

Algorithms Explained

Algorithms Explained

In the previous lesson, you learned that data is the fuel for AI. But fuel alone does not move a car - you need an engine. In AI, that engine is an algorithm. Every time an AI system makes a prediction, recommends a video, or detects spam, an algorithm is doing the heavy lifting behind the scenes.

What Is an Algorithm?

An algorithm is simply a step-by-step set of instructions for solving a problem. You follow algorithms every day without realising it.

  • A recipe is an algorithm: combine ingredients in a specific order to produce a cake.
  • Flat-pack furniture instructions are an algorithm: follow each step to build a bookshelf.
  • Driving directions are an algorithm: turn left, go straight, turn right, arrive.

The key idea is that an algorithm must be precise, ordered, and repeatable - anyone following the same steps should get the same result.

A flowchart showing a simple decision algorithm: Is it raining? If yes, take an umbrella. If no, wear sunglasses.
An algorithm is a clear set of instructions - like a flowchart that guides you to a decision.
๐Ÿคฏ

The word "algorithm" comes from the name of a 9th-century Persian mathematician, Muhammad ibn Musa al-Khwarizmi, who wrote one of the first books on systematic problem-solving.

Everyday Algorithm Examples

Before we dive into AI, let us look at two simple algorithms you already understand intuitively.

Sorting a Hand of Cards

When you pick up a hand of playing cards and arrange them in order, you are running a sorting algorithm:

  1. Look at the first two cards. Swap them if they are out of order.
  2. Move to the next pair. Compare and swap again.
  3. Repeat until the entire hand is sorted.

This is essentially how bubble sort works - one of the simplest sorting algorithms in computer science.

Finding a Word in a Dictionary

You do not start at page one and read every word. Instead, you:

  1. Open the dictionary roughly in the middle.
  2. Check if the word you need comes before or after that page.
Lesson 2 of 160% complete
โ†How Data Powers AI

Discussion

Sign in to join the discussion

Suggest an edit to this lesson
  • Discard the half you do not need and repeat.
  • This is called binary search, and it is incredibly efficient. It can find any word among a million entries in about 20 steps.

    ๐Ÿง Quick Check

    Why is binary search faster than reading every entry from the start?

    How Algorithms Power AI

    AI algorithms are more sophisticated than sorting cards, but the principle is the same: follow structured steps to reach an answer. Here are two foundational AI algorithms.

    Decision Trees

    A decision tree asks a series of yes-or-no questions to classify something.

    Example - Is this email spam?

    1. Does the subject line contain "FREE MONEY"? โ†’ If yes, likely spam.
    2. Is the sender in your contacts? โ†’ If yes, probably not spam.
    3. Does it contain more than five links? โ†’ If yes, lean towards spam.

    Each question is a branch, and each final answer is a leaf. Decision trees are easy to understand, which makes them popular when humans need to explain the AI's reasoning.

    K-Nearest Neighbours (KNN)

    KNN classifies something by looking at the closest examples it has already seen.

    Imagine you move to a new neighbourhood and want to know if a house is expensive or affordable. You look at the five nearest houses (your "neighbours") and check their prices. If most are expensive, you predict yours is too.

    KNN works exactly the same way with data points - it finds the K closest examples and takes a vote.

    ๐Ÿค”
    Think about it:

    If you asked three friends for a film recommendation and two of them suggested the same film, you would probably watch that one. That is the core idea behind KNN - majority rules among your nearest neighbours.

    ๐Ÿง Quick Check

    In a K-Nearest Neighbours algorithm with K=5, how does the model make its prediction?

    Big O Notation: Fast vs Slow Algorithms

    Not all algorithms are equally fast. Computer scientists use Big O notation to describe how an algorithm's speed changes as the data grows.

    | Notation | Name | Example | Speed | |----------|------|---------|-------| | O(1) | Constant | Looking up a value by index | โšก Instant | | O(log n) | Logarithmic | Binary search | ๐Ÿš€ Very fast | | O(n) | Linear | Reading every item in a list | ๐Ÿƒ Decent | | O(nยฒ) | Quadratic | Comparing every item to every other | ๐Ÿข Slow |

    You do not need to memorise the maths. The key insight is this: as your dataset grows, a poorly chosen algorithm can go from fast to impossibly slow.

    ๐Ÿคฏ

    Google processes over 8.5 billion searches per day. If their search algorithm were O(nยฒ) instead of highly optimised, a single search could take hours instead of milliseconds.

    ๐Ÿ’ก

    Big O notation is not about exact speed - it is about how speed scales. An O(n) algorithm might be slow on tiny data but will always outperform an O(nยฒ) algorithm as the dataset grows large.

    Why Choosing the Right Algorithm Matters

    There is no single "best" algorithm. The right choice depends on:

    • The problem type - Are you classifying images or predicting numbers?
    • The data size - Some algorithms struggle with millions of rows.
    • Explainability needs - Can you use a black box, or must you explain every decision?
    • Speed requirements - Does the answer need to arrive in milliseconds or can it take minutes?

    A decision tree might be perfect for a simple loan approval system where transparency is required. But for recognising objects in a photo, you would need a neural network - which we will explore in the next lesson.

    ๐Ÿค”
    Think about it:

    A hospital needs an AI to help diagnose patients. Should they choose an algorithm that is highly accurate but impossible to explain, or one that is slightly less accurate but shows its reasoning clearly? What are the trade-offs?

    ๐Ÿง Quick Check

    Which factor is LEAST important when choosing an AI algorithm?

    Key Takeaways

    • An algorithm is a step-by-step set of instructions for solving a problem.
    • Decision trees classify by asking sequential yes/no questions.
    • K-Nearest Neighbours classifies by looking at the closest known examples.
    • Big O notation tells us how an algorithm's speed scales with data size.
    • Choosing the right algorithm depends on the problem, data, and constraints.

    Next, we will look at the most powerful family of algorithms in modern AI: neural networks.