Grokking AI Algorithms

An illustrated guide

Learn the algorithms that power search, optimization, machine learning, deep learning, and generative AI.

Grokking AI Algorithms book cover
What you'll learn

The algorithms that underpin AI, from classic to cutting-edge.

Artificial intelligence algorithms are the backbone of search and optimization, deep learning, reinforcement learning, and, of course, generative AI. Grokking AI Algorithms, Second Edition introduces the most important AI algorithms using relatable illustrations, interesting examples, and thought-provoking exercises. Written in simple language and with lots of visual references and hands-on code examples, it helps you build a natural intuition into how intelligent systems learn, plan, and adapt. This second edition has been thoroughly revised, with new chapters on large language models, image generation, and more.

Search fundamentals illustration

Search fundamentals

Learn the fundamentals of search algorithms.

Game-playing AI illustration

Game-playing AI

Build intelligent agents to solve puzzles and play games.

Evolutionary algorithms illustration

Evolutionary algorithms

Find solutions using the theory of evolution and genetic algorithms.

Swarm intelligence illustration

Swarm intelligence

Explore AI through collective behavior in nature like ant colonies and bird flocking.

Machine learning illustration

Machine learning

Make predictions with regression and decision trees.

Neural networks illustration

Neural networks

Understand how AI learns and recognize patterns with neural networks.

Reinforcement learning illustration

Reinforcement learning

See how AI improves through trial and error with reinforcement learning.

Large language models illustration

Large language models

Build a LLM from scratch and understand how they work.

Image generation illustration

Image generation

Create an image diffusion model to generate images from text prompts.

Who it's for

For people in tech.

Grokking AI Algorithms is for software developers and anyone in the software industry who wants to grasp the intuitions and uncover the workings and algorithms behind AI through practical examples and visual explanations instead of going through theoretical deep dives and mathematical proofs.

Illustration highlighting who the book is for

Ideal for

  • Developers building AI-powered features and tools.
  • Analysts designing AI capabilities in software products.
  • Leaders who need shared vocabulary with engineering.
  • Students learning about computer science and AI.
  • Enthusiasts curious about how AI works under the hood.
Inside the book

From the fundamentals to generative AI.

Chapter 1 thumbnail
Chapter 1

Intuition of AI

Explore what intelligence means, why data is the fuel of AI, and how algorithms act like recipes. Then trace the progression from classic search and evolutionary methods to modern machine learning, deep learning, and generative AI.

Chapter 2 thumbnail
Chapter 2

Search fundamentals

See how planning becomes a sequence of search steps and why we constantly revise plans in dynamic environments. Compare breadth-first and depth-first search in a maze and watch how each explores routes to reach a goal efficiently.

Chapter 3 thumbnail
Chapter 3

Intelligent search

Go beyond blind search with heuristics—rules of thumb that score states when perfect solutions are impractical. Step into adversarial search and watch minimax evaluate game trees as you play Connect Four against an AI opponent.

Chapter 4 thumbnail
Chapter 4

Evolutionary algorithms

Learn how variation, selection, and mutation turn evolution into a powerful search strategy for huge solution spaces. Apply genetic algorithms to the knapsack problem and tune fitness, crossover, and mutation to improve solutions over generations.

Chapter 5 thumbnail
Chapter 5

Advanced evolutionary approaches

Extend the genetic algorithm toolkit by exploring how solutions are encoded for different problems. Try real-number, order, and tree encodings and see how representation choices shape what evolution can discover.

Chapter 6 thumbnail
Chapter 6

Swarm intelligence: Ants

Discover how simple agents like ants use pheromones to create intelligent group behavior. Use ant colony optimization to find efficient routes between attractions and compare it to your own path-planning.

Chapter 7 thumbnail
Chapter 7

Swarm intelligence: Particles

Learn particle swarm optimization through the physics of bird flocks—alignment, cohesion, and separation. Balance aluminum and plastic to optimize a drone while PSO blends inertia, cognitive, and social forces.

Chapter 8 thumbnail
Chapter 8

Machine learning

See how machine learning uncovers patterns in data and chooses the right algorithm for the task. Fit a linear regression model to diamond price vs. carat and learn how slopes, intercepts, and learning rate shape predictions.

Chapter 9 thumbnail
Chapter 9

Artificial neural networks

Connect biological neurons to the perceptron and see how weighted inputs and activation functions produce learning. Build a small neural network that predicts accidents from driving conditions and watch it improve through training.

Chapter 10 thumbnail
Chapter 10

Reinforcement learning

Explore reinforcement learning as reward-driven behavior and map it to the Markov decision process. Train a Q-learning agent in a parking-lot grid world and see how Q-tables store better choices over time.

Chapter 11 thumbnail
Chapter 11

Large Language Models (LLMs)

Build intuition for language modeling by turning sentences into bigrams and probability tables. Train a tiny model on sample text and watch next-word predictions emerge, just like autocomplete.

Chapter 12 thumbnail
Chapter 12

Generative Image Models

Understand diffusion as iterative denoising that reveals structure inside random noise. Follow the sculptor analogy and tune noise and learning rate to see how images gradually sharpen over steps.

About the author

Rishal Hurbans

Rishal Hurbans

Rishal is a technologist, entrepreneur, and author who is passionate about crafting innovative products and meaningful experiences. He has over a decade of expertise delivering diverse technology solutions across the finance, health, agriculture, mining, and aviation industries. Rishal is driven by a deep interest in making complex concepts accessible through visual, intuitive, and practical experiences. Rishal continues to build at the intersection of design, technology, and creativity, guided by the belief that technology should amplify human potential.