# Algorithms for PHP Developers

[Original page](https://codewithphp.com/series/php-algorithms/)

> Master essential computer science algorithms with practical PHP implementations—from sorting and searching to graphs and dynamic programming.

![Algorithms for PHP Developers](/images/php-algorithms/chapter-00-quick-start-guide-hero-full.webp)

# Algorithms for PHP Developers <span class="difficulty-badge difficulty-intermediate">Intermediate</span>

## Overview

Welcome to **Algorithms for PHP Developers** — a comprehensive, hands-on course that teaches you essential computer science algorithms through practical PHP implementations. Whether you're preparing for technical interviews, optimizing production applications, or simply wanting to understand how algorithms work under the hood, this series will give you the knowledge and skills to solve complex problems efficiently.

Algorithms and data structures form the foundation of computer science and software engineering. Understanding them transforms you from someone who writes code that works to someone who writes code that scales, performs efficiently, and handles edge cases gracefully. Yet many self-taught developers—and even experienced PHP developers—lack formal CS training and feel intimidated by algorithmic concepts.

This series bridges that gap. You'll learn classic algorithms explained in developer-friendly terms, implemented in modern PHP 8.6, and applied to real-world scenarios. From sorting thousands of records to finding the shortest path in a routing system, from optimizing database queries to building recommendation engines—you'll understand when and how to apply each algorithm effectively.

By the end of this series, you'll have mastered Big O notation for analyzing complexity, implemented dozens of algorithms from scratch, explored advanced data structures, and built practical projects that demonstrate real-world applications. More importantly, you'll have developed algorithmic thinking—the ability to break down complex problems and design efficient solutions.

## Who This Is For

This series is designed for:

- **PHP developers** (intermediate to advanced) who want to level up their problem-solving skills
- **Self-taught programmers** looking to fill in computer science fundamentals
- **Interview preppers** who need to master algorithms in a PHP context
- **Web developers** wanting to optimize application performance and scalability
- **Anyone transitioning** from "code that works" to "code that scales efficiently"

You don't need a computer science degree or advanced mathematics knowledge. If you're comfortable with PHP syntax, arrays, loops, functions, and basic object-oriented programming, you're ready to start.

## Prerequisites

**Software Requirements:**

- **PHP 8.6** (we'll use modern PHP features throughout)
- **Composer** (PHP's dependency manager for some chapters)
- **Text editor or IDE** (VS Code, PhpStorm, or your preferred editor)
- **Terminal/Command line** access

**Time Commitment:**

- **Estimated total**: 40–50 hours to complete all chapters (including appendices)
- **Per chapter**: 30 minutes to 90 minutes
- **Core learning path (Beginner)**: 12 hours
- **Interview preparation path**: 25 hours
- **Production optimization path**: 15 hours
- **Complete mastery path**: 40+ hours

**Skill Assumptions:**

- You can write PHP functions and classes confidently
- You understand arrays, loops, and conditional statements
- You're familiar with basic recursion concepts
- You can read and understand PHP documentation
- No prior algorithms or data structures knowledge required

## What You'll Build


By working through this series, you will:

1. **Implement classic algorithms from scratch** in modern PHP 8.6:
   - 6 sorting algorithms with performance comparisons
   - 4 searching techniques for different use cases
   - 6 data structures (linked lists, stacks, queues, trees)
   - 5 graph algorithms for traversal and pathfinding
   - Dynamic programming solutions for optimization problems
   - Advanced string matching and pattern recognition

2. **Build practical projects** demonstrating real-world applications:
   - Product recommendation engine using collaborative filtering
   - Social feed ranking algorithm
   - Search engine with full-text indexing
   - Data pipeline for ETL processing
   - Route optimization system
   - Caching strategies for high-performance applications

3. **Master algorithmic analysis**:
   - Big O notation for time and space complexity
   - Benchmarking framework for measuring performance
   - Trade-off analysis for choosing the right algorithm
   - Performance optimization techniques

4. **Gain interview-ready skills**:
   - Common interview questions solved in PHP
   - Problem-solving strategies and patterns
   - Time/space complexity analysis for any algorithm
   - Communication techniques for explaining your approach

Every code example is production-ready, following PHP 8.6 best practices, and includes comprehensive explanations of how and why it works.

## Learning Objectives

By the end of this series, you will be able to:

- **Analyze algorithm efficiency** using Big O notation with confidence
- **Implement sorting algorithms** and know which to use when
- **Master search techniques** from linear to binary to hash-based lookups
- **Build custom data structures** when PHP's arrays aren't enough
- **Solve problems recursively** and understand when recursion makes sense
- **Traverse and search graphs** for routing and relationship problems
- **Apply dynamic programming** to optimize complex calculations
- **Choose the right algorithm** for any given problem and dataset size
- **Optimize existing code** by identifying bottlenecks and applying better algorithms
- **Ace technical interviews** by solving algorithmic problems confidently in PHP

## How This Series Works

This series follows a **progressive, hands-on approach**: you'll learn each algorithm by understanding the concept, implementing it yourself in PHP, analyzing its performance, and seeing real-world applications.

Each chapter includes:

- **Clear explanations** of algorithms using developer-friendly language
- **Step-by-step implementations** in modern PHP 8.6
- **Big O analysis** for understanding complexity
- **Practical examples** showing when and why to use each algorithm
- **Performance comparisons** with benchmarking results
- **Hands-on exercises** to reinforce learning
- **Troubleshooting tips** for common implementation challenges
- **Further reading** for deeper exploration

We'll start with fundamentals (Big O notation, benchmarking), progress through classic algorithms (sorting, searching), explore data structures (arrays, trees, graphs), and finish with advanced topics (concurrency, probabilistic algorithms, real-world case studies).

::: tip
Type the code yourself instead of copy-pasting. Understanding algorithms requires hands-on practice—implementing, testing, breaking, and fixing. Build muscle memory and debugging skills by typing every example.
:::

## Quick Start

Want to see algorithmic thinking in action right now? Here's a 2-minute example comparing approaches:

```php
<?php
// Problem: Find if a number exists in a sorted array
$numbers = range(1, 1000000); // One million numbers (already sorted)
$target = 750000;

// ❌ Naive approach: O(n) - linear search
$start = microtime(true);
$found = in_array($target, $numbers, true);
echo "Linear search: " . round((microtime(true) - $start) * 1000, 2) . "ms\n";

// ✅ Optimized approach: O(log n) - binary search (array must be sorted)
function binarySearch(array $arr, int $target): ?int {
    $left = 0;
    $right = count($arr) - 1;
    while ($left <= $right) {
        $mid = (int)(($left + $right) / 2);
        if ($arr[$mid] === $target) return $mid;
        if ($arr[$mid] < $target) $left = $mid + 1;
        else $right = $mid - 1;
    }
    return null;
}

$start = microtime(true);
$index = binarySearch($numbers, $target);
echo "Binary search: " . round((microtime(true) - $start) * 1000, 2) . "ms\n";

// Expected: Binary search is ~1000x faster!
```

**What's Next?**  
That's algorithmic thinking: understanding that algorithm choice dramatically affects performance. Head to [Chapter 00: Quick Start Guide](/series/php-algorithms/chapters/00-quick-start-guide/) for a 5-minute overview, or start with [Chapter 01: Algorithm Complexity & Big O Notation](/series/php-algorithms/chapters/01-algorithm-complexity-big-o-notation/) for comprehensive learning.

---

## Learning Paths & Chapters

Choose your learning path based on your goals and experience level, or explore all chapters below.

::: tip Recommended Learning Paths
- **Absolute Beginner** (~12 hours): Chapters 00, 01, 02, 03, 06, 12, 16, 18, 29
- **Interview Preparation** (~25 hours): Chapters 00-03, 06-15, 16, 19-20, 23-27, 31
- **Production Optimization** (~15 hours): Chapters 00, 03, 14, 28-31, 36, + Appendix B
- **Complete Mastery** (~40 hours): All chapters 00-36 + all appendices
:::

### Part 0: Getting Started (Chapter 00)

Get oriented quickly with common scenarios and algorithm selection.

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-00-quick-start-guide-hero-thumbnail.webp" alt="Chapter 00 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/00-quick-start-guide">00 — Quick Start Guide</a></h4>
    <p style="margin-bottom: 0;"><strong>NEW!</strong> Start here if you have 5 minutes. Common scenarios, algorithm mapping tables, and copy-paste ready solutions for immediate problem-solving. Discover which algorithm to use when, and see real-world use cases mapped to specific chapters for fast navigation.</p>
  </div>
</div>

### Part 1: Foundation (Chapters 01–05)

Build essential knowledge for algorithmic thinking and analysis.

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-00-introduction-hero-thumbnail.webp" alt="Chapter 01 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/01-algorithm-complexity-big-o-notation">01 — Algorithm Complexity & Big O Notation</a></h4>
    <p style="margin-bottom: 0;">Master Big O notation for analyzing algorithm efficiency. Understand time and space complexity, compare algorithms using O(1), O(n), O(log n), and O(n²) notation. Learn to identify bottlenecks and choose efficient solutions based on data size and performance requirements.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-01-complexity-big-o-hero-thumbnail.webp" alt="Chapter 02 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/02-benchmarking-performance-testing">02 — Benchmarking & Performance Testing</a></h4>
    <p style="margin-bottom: 0;">Build a benchmarking framework to measure real-world algorithm performance. Learn to profile PHP code, measure execution time accurately, handle timing variations, and interpret benchmark results. Understand when theoretical Big O matches practice and when it doesn't.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-02-benchmarking-hero-thumbnail.webp" alt="Chapter 03 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/03-recursion-fundamentals">03 — Recursion Fundamentals</a></h4>
    <p style="margin-bottom: 0;">Master recursive thinking and implementation. Understand base cases, recursive cases, call stacks, and when recursion is the appropriate solution. Implement classic recursive algorithms (factorial, fibonacci, tree traversal) and learn to convert between recursive and iterative approaches.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-03-recursion-hero-thumbnail.webp" alt="Chapter 04 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/04-problem-solving-strategies">04 — Problem-Solving Strategies</a></h4>
    <p style="margin-bottom: 0;">Develop systematic approaches to algorithm problems. Learn divide-and-conquer, greedy algorithms, brute force, and pattern recognition strategies. Practice breaking down complex problems into manageable steps and choosing the right algorithmic approach for each situation.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-04-problem-solving-hero-thumbnail.webp" alt="Chapter 05 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/05-bubble-sort-selection-sort">05 — Bubble Sort & Selection Sort</a></h4>
    <p style="margin-bottom: 0;">Implement and understand simple sorting algorithms. Learn their O(n²) time complexity and when (not) to use them. Build intuition for how sorting works by understanding these foundational algorithms before moving to more efficient approaches.</p>
  </div>
</div>

### Part 2: Sorting Algorithms (Chapters 06–11)

Master sorting techniques from simple to advanced.

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-05-bubble-selection-sort-hero-thumbnail.webp" alt="Chapter 06 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/06-insertion-sort-merge-sort">06 — Insertion Sort & Merge Sort</a></h4>
    <p style="margin-bottom: 0;">Explore more efficient sorting techniques. Understand divide-and-conquer strategies with merge sort (O(n log n)) and when insertion sort excels for small or nearly-sorted arrays. Learn about stable sorting and its practical implications.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-06-insertion-merge-sort-hero-thumbnail.webp" alt="Chapter 07 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/07-quick-sort-pivot-strategies">07 — Quick Sort & Pivot Strategies</a></h4>
    <p style="margin-bottom: 0;">Master one of the most popular sorting algorithms used in production. Learn partitioning, pivot selection strategies (first, last, median-of-three, random), and optimization techniques. Understand why quicksort is often faster than merge sort in practice.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-07-quick-sort-hero-thumbnail.webp" alt="Chapter 08 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/08-heap-sort-priority-queues">08 — Heap Sort & Priority Queues</a></h4>
    <p style="margin-bottom: 0;">Build a binary heap data structure and use it for efficient O(n log n) sorting. Understand heap properties (max-heap, min-heap), heapify operations, and implement priority queues for task scheduling and event-driven systems.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-08-heap-sort-hero-thumbnail.webp" alt="Chapter 09 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/09-comparing-sorting-algorithms">09 — Comparing Sorting Algorithms</a></h4>
    <p style="margin-bottom: 0;">Benchmark all sorting algorithms against each other with different data sizes and patterns. Learn which to use in different scenarios: nearly-sorted data, random data, reverse-sorted data. Understand trade-offs between time complexity, space complexity, and stability.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-09-comparing-sorts-hero-thumbnail.webp" alt="Chapter 10 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/10-php-built-in-sorting-functions">10 — PHP's Built-in Sorting Functions</a></h4>
    <p style="margin-bottom: 0;">Explore PHP's sort(), usort(), asort(), ksort(), and array sorting functions. Understand their implementations, performance characteristics, and best practices. Learn when to use built-in functions versus custom implementations.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-10-php-builtin-sorting-hero-thumbnail.webp" alt="Chapter 11 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/11-linear-search-variants">11 — Linear Search & Variants</a></h4>
    <p style="margin-bottom: 0;">Understand the simplest search algorithm with O(n) complexity and its variations. Learn sentinel search for optimization, early termination strategies, and when linear search is actually the best choice (small datasets, unsorted data).</p>
  </div>
</div>

### Part 3: Searching Algorithms (Chapters 12–15)

Efficient techniques for finding data in collections.

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-11-linear-search-hero-thumbnail.webp" alt="Chapter 12 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/12-binary-search">12 — Binary Search</a></h4>
    <p style="margin-bottom: 0;">Master the efficient O(log n) divide-and-conquer search algorithm for sorted arrays. Implement iterative and recursive versions, handle edge cases, and learn variations (first occurrence, last occurrence, insertion point).</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-12-binary-search-hero-thumbnail.webp" alt="Chapter 13 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/13-hash-tables-hash-functions">13 — Hash Tables & Hash Functions</a></h4>
    <p style="margin-bottom: 0;">Build a hash table from scratch for O(1) average-case lookups. Learn hash function design, collision handling with chaining and open addressing, load factors, and when to use hash tables versus arrays in PHP.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-13-hash-tables-hero-thumbnail.webp" alt="Chapter 14 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/14-string-search-algorithms">14 — String Search Algorithms</a></h4>
    <p style="margin-bottom: 0;">Implement pattern matching algorithms: naive search, Knuth-Morris-Pratt (KMP), and Boyer-Moore. Build a simple grep-like tool and understand which algorithm works best for different text search scenarios.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-14-string-search-hero-thumbnail.webp" alt="Chapter 15 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/15-arrays-dynamic-arrays">15 — Arrays & Dynamic Arrays</a></h4>
    <p style="margin-bottom: 0;">Deep dive into arrays: how they work in memory, dynamic resizing strategies (doubling capacity), amortized analysis, and PHP's unique array implementation (ordered hash map). Understand when PHP arrays excel and when custom structures are needed.</p>
  </div>
</div>

### Part 4: Data Structures (Chapters 16–21)

Build fundamental data structures from scratch.

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-15-arrays-hero-thumbnail.webp" alt="Chapter 16 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/16-linked-lists">16 — Linked Lists</a></h4>
    <p style="margin-bottom: 0;">Build singly and doubly linked lists from scratch using PHP objects. Understand pointer manipulation, node operations (insert, delete, search), and when linked lists outperform arrays (frequent insertions/deletions at arbitrary positions).</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-16-linked-lists-hero-thumbnail.webp" alt="Chapter 17 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/17-stacks-queues">17 — Stacks & Queues</a></h4>
    <p style="margin-bottom: 0;">Implement LIFO (Last In First Out) stacks and FIFO (First In First Out) queues. Build practical applications: expression evaluator (postfix notation), task scheduler, browser history, and undo/redo functionality.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-17-stacks-queues-hero-thumbnail.webp" alt="Chapter 18 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/18-trees-binary-search-trees">18 — Trees & Binary Search Trees</a></h4>
    <p style="margin-bottom: 0;">Learn tree terminology (root, leaf, parent, child, height, depth) and implement a Binary Search Tree with O(log n) average-case operations. Master insertion, deletion, search, and understand BST properties and degenerate cases.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-18-binary-search-trees-hero-thumbnail.webp" alt="Chapter 19 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/19-tree-traversal-algorithms">19 — Tree Traversal Algorithms</a></h4>
    <p style="margin-bottom: 0;">Implement in-order, pre-order, post-order (depth-first), and level-order (breadth-first) traversals. Use them to solve practical problems: expression trees, directory structures, syntax trees, and hierarchical data processing.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-19-tree-traversal-hero-thumbnail.webp" alt="Chapter 20 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/20-balanced-trees-avl-red-black">20 — Balanced Trees (AVL & Red-Black)</a></h4>
    <p style="margin-bottom: 0;">Understand self-balancing trees that guarantee O(log n) operations. Learn AVL tree rotations, Red-Black tree properties, when balanced trees are essential (databases, language implementations), and trade-offs versus simple BSTs.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-20-balanced-trees-hero-thumbnail.webp" alt="Chapter 21 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/21-graph-representations">21 — Graph Representations</a></h4>
    <p style="margin-bottom: 0;">Model graphs using adjacency matrices (dense graphs) and adjacency lists (sparse graphs). Understand directed vs undirected graphs, weighted vs unweighted edges, and choose the right representation based on graph density and operations needed.</p>
  </div>
</div>

### Part 5: Graph Algorithms (Chapters 22–25)

Traverse and analyze networks and relationships.

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-21-graph-representations-hero-thumbnail.webp" alt="Chapter 22 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/22-depth-first-search">22 — Depth-First Search (DFS)</a></h4>
    <p style="margin-bottom: 0;">Implement DFS for graph traversal using recursion and stacks. Use it to detect cycles, find connected components, solve maze problems, perform topological sorting, and explore all paths in a graph.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-22-depth-first-search-hero-thumbnail.webp" alt="Chapter 23 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/23-breadth-first-search">23 — Breadth-First Search (BFS)</a></h4>
    <p style="margin-bottom: 0;">Master BFS for finding shortest paths in unweighted graphs. Build practical applications: web crawler, social network analyzer (degrees of separation), level-order traversal, and minimum spanning tree discovery.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-23-breadth-first-search-hero-thumbnail.webp" alt="Chapter 24 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/24-dijkstra-shortest-path">24 — Dijkstra's Shortest Path</a></h4>
    <p style="margin-bottom: 0;">Find shortest paths in weighted graphs using Dijkstra's algorithm with priority queues. Implement route planning applications (GPS navigation, network routing), understand limitations (no negative weights), and compare with A* algorithm.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-24-dijkstra-hero-thumbnail.webp" alt="Chapter 25 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/25-dynamic-programming-fundamentals">25 — Dynamic Programming Fundamentals</a></h4>
    <p style="margin-bottom: 0;">Learn memoization (top-down) and tabulation (bottom-up) approaches to optimization. Solve classic problems: fibonacci, coin change, knapsack, longest common subsequence. Transform exponential-time recursive solutions into polynomial-time iterative ones.</p>
  </div>
</div>

### Part 6: Dynamic Programming (Chapters 26–27)

Optimize complex problems with memoization and tabulation.

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-25-dynamic-programming-hero-thumbnail.webp" alt="Chapter 26 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/26-advanced-dynamic-programming">26 — Advanced Dynamic Programming</a></h4>
    <p style="margin-bottom: 0;">Master interval DP, bitmask DP, and multi-dimensional optimization problems. Solve traveling salesman problem (TSP), edit distance (Levenshtein), matrix chain multiplication, and other complex optimization scenarios common in interviews and production code.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-26-advanced-dp-hero-thumbnail.webp" alt="Chapter 27 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/27-caching-memoization-strategies">27 — Caching & Memoization Strategies</a></h4>
    <p style="margin-bottom: 0;">Implement LRU (Least Recently Used) cache, TTL (Time To Live) cache, and integrate with Redis/Memcached. Apply caching strategies to real PHP applications for API responses, database queries, computed results, and session management.</p>
  </div>
</div>

### Part 7: Practical Applications (Chapters 28–30)

Apply algorithms to real-world PHP development scenarios.

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-27-caching-hero-thumbnail.webp" alt="Chapter 28 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/28-algorithm-selection-guide">28 — Algorithm Selection Guide</a></h4>
    <p style="margin-bottom: 0;">Decision trees for choosing the right algorithm for your problem. Learn pattern recognition, complexity constraints, data size considerations, and practical trade-offs. Map common problems (sorting, searching, optimization) to optimal algorithm choices.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-28-algorithm-selection-hero-thumbnail.webp" alt="Chapter 29 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/29-performance-optimization">29 — Performance Optimization</a></h4>
    <p style="margin-bottom: 0;">Profile PHP code with Xdebug and Blackfire, benchmark algorithms, optimize memory usage, and apply PHP-specific performance techniques (OPcache, JIT compilation, preloading). Identify bottlenecks and measure improvements systematically.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-29-performance-optimization-hero-thumbnail.webp" alt="Chapter 30 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/30-real-world-case-studies">30 — Real-World Case Studies</a></h4>
    <p style="margin-bottom: 0;">Complete implementations of production scenarios: e-commerce product recommendations (collaborative filtering), social feed ranking algorithms, search engine indexing, ETL data pipelines. See how multiple algorithms combine to solve complex real-world problems.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-30-case-studies-hero-thumbnail.webp" alt="Chapter 31 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/30-real-world-case-studies/">31 — Real-World Case Studies</a></h4>
    <p style="margin-bottom: 0;">Complete implementations of production scenarios: e-commerce product recommendations (collaborative filtering), social feed ranking algorithms, search engine indexing, ETL data pipelines. See how multiple algorithms combine to solve complex real-world problems.</p>
  </div>
</div>

### Part 8: Advanced Topics (Chapters 31–36)

Explore cutting-edge algorithms for specialized applications.

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-31-concurrent-algorithms-hero-thumbnail.webp" alt="Chapter 31 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/31-concurrent-algorithms">31 — Concurrent Algorithms</a></h4>
    <p style="margin-bottom: 0;"><strong>NEW!</strong> Async/await patterns with Amphp/ReactPHP, parallel processing with multiple processes, worker pools for job distribution, and concurrent data structures (thread-safe queues, atomic operations). Handle race conditions and synchronization in PHP.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-32-probabilistic-algorithms-hero-thumbnail.webp" alt="Chapter 32 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/32-probabilistic-algorithms">32 — Probabilistic Algorithms</a></h4>
    <p style="margin-bottom: 0;"><strong>NEW!</strong> Space-efficient probabilistic data structures: Bloom filters (membership testing), HyperLogLog (cardinality estimation), count-min sketch (frequency counting), and skip lists. Trade perfect accuracy for memory efficiency in big data scenarios.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-33-string-algorithms-hero-thumbnail.webp" alt="Chapter 33 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/33-string-algorithms-deep-dive">33 — String Algorithms Deep Dive</a></h4>
    <p style="margin-bottom: 0;"><strong>NEW!</strong> Advanced string matching: Aho-Corasick (multi-pattern search), suffix trees and arrays (substring queries), Rabin-Karp (rolling hash), and Levenshtein distance (fuzzy matching). Essential for search engines, DNA sequence analysis, and text processing.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-34-geometric-algorithms-hero-thumbnail.webp" alt="Chapter 34 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/34-geometric-algorithms">34 — Geometric Algorithms</a></h4>
    <p style="margin-bottom: 0;"><strong>NEW!</strong> Computational geometry basics: convex hull (Graham scan), line intersection detection, point in polygon testing, closest pair of points, and Voronoi diagrams. Applications in mapping, computer graphics, GIS systems, and collision detection.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-35-cryptographic-algorithms-hero-thumbnail.webp" alt="Chapter 35 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/35-cryptographic-algorithms">35 — Cryptographic Algorithms</a></h4>
    <p style="margin-bottom: 0;"><strong>NEW!</strong> Cryptographic hash functions (SHA-256, bcrypt), symmetric and asymmetric encryption basics, secure random number generation, digital signatures, and key derivation functions. Understand security primitives used in authentication, password storage, and data protection.</p>
  </div>
</div>

<div style="display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem;">
  <img src="/images/php-algorithms/chapter-36-stream-processing-hero-thumbnail.webp" alt="Chapter 36 thumbnail" style="width: 180px; height: auto; flex-shrink: 0; border-radius: 4px;" />
  <div>
    <h4 style="margin-top: 0;"><a href="/series/php-algorithms/chapters/36-stream-processing-algorithms">36 — Stream Processing Algorithms</a></h4>
    <p style="margin-bottom: 0;"><strong>NEW!</strong> Process infinite data streams efficiently: sliding window algorithms, rate limiting mechanisms, lossy counting for frequent items, and real-time aggregation. Essential for analytics dashboards, monitoring systems, and event processing. See Chapter 32 for probabilistic stream algorithms like reservoir sampling.</p>
  </div>
</div>

---

## Appendices

Quick reference materials to support your learning journey.

- **[Appendix A: Complexity Cheat Sheet](/series/php-algorithms/appendices/appendix-a-complexity-cheat-sheet/)** — Quick reference for Big O complexity, common algorithm complexities, and decision guides
- **[Appendix B: PHP Performance Tips](/series/php-algorithms/appendices/appendix-b-php-performance-tips/)** — PHP-specific optimization techniques, OPcache configuration, and production best practices
- **[Appendix C: Glossary](/series/php-algorithms/appendices/appendix-c-glossary/)** — Comprehensive glossary of algorithm and data structure terms with examples
- **[Appendix D: Further Reading](/series/php-algorithms/appendices/appendix-d-further-reading/)** — Curated resources, books, courses, and websites for continued learning

---

## Frequently Asked Questions

**I'm not a computer science graduate. Can I really learn algorithms?**  
Absolutely! This series is designed for self-taught developers and doesn't assume formal CS training. We explain concepts in developer-friendly terms with practical PHP examples. If you can write PHP functions and use arrays, you're ready to start.

**Do I need to know math to understand algorithms?**  
Not advanced math. You'll encounter basic arithmetic and occasionally logarithms, but everything is explained in practical terms. We focus on understanding concepts rather than mathematical proofs.

**How long will it take to become proficient?**  
The Beginner path takes ~12 hours and gives you solid fundamentals. For interview preparation, expect ~25 hours. Complete mastery of all chapters takes ~40 hours. But you'll see immediate benefits even after the first few chapters.

**Should I memorize all these algorithms?**  
No! Focus on understanding the concepts, when to use each algorithm, and how to analyze complexity. Professional developers look up implementation details regularly. Understanding trade-offs is more valuable than memorization.

**Are these algorithms practical for web development?**  
Very! You'll learn sorting for data presentation, searching for lookups, hash tables for caching, graph algorithms for routing, and more. Chapter 31 specifically covers real-world web application scenarios.

**What about PHP's built-in functions like `sort()` and `array_search()`?**  
PHP's built-in functions are optimized and should be your first choice. However, understanding the algorithms behind them helps you:
- Choose the right function for your use case
- Understand performance implications
- Solve problems when built-ins aren't enough
- Ace technical interviews

**Will this help me pass coding interviews?**  
Yes! The Interview Preparation path is specifically designed for technical interviews. You'll solve common questions, learn to communicate your approach, and analyze complexity—exactly what interviewers look for.

**Can I skip chapters?**  
The Quick Start (Chapter 00) helps you navigate to specific topics. Foundation chapters (01-05) are essential. After that, you can jump to specific algorithms you need, though concepts build on each other.

**How often should I practice?**  
Consistent, spaced practice works best. Try 2-3 chapters per week with hands-on implementation. Spend 30-60 minutes coding each algorithm yourself rather than just reading.

**What comes after this series?**  
You'll be prepared for advanced topics like distributed algorithms, machine learning, compiler design, or whatever interests you. Check out our [AI/ML for PHP Developers](/series/ai-ml-php-developers/) series to apply algorithmic thinking to machine learning.

## Getting Help

**Stuck on something?** Here's where to get help:

- **Check the appendices first**:
  - [Appendix A: Complexity Cheat Sheet](/series/php-algorithms/appendices/appendix-a-complexity-cheat-sheet/) for Big O reference
  - [Appendix C: Glossary](/series/php-algorithms/appendices/appendix-c-glossary/) for term definitions
  - [Appendix B: PHP Performance Tips](/series/php-algorithms/appendices/appendix-b-php-performance-tips/) for optimization
- **Review chapter troubleshooting sections** for common implementation issues
- **Check code samples** in `/code-samples/php-algorithms/` for working examples
- **PHP Manual**: [php.net](https://www.php.net/) for language reference
- **GitHub Discussions**: [Ask questions and share progress](https://github.com/dalehurley/codewithphp/discussions)
- **Report issues**: [Open an issue](https://github.com/dalehurley/codewithphp/issues) for unclear explanations or broken examples

## Related Resources

Want to dive deeper? These resources complement the series:

### Algorithm Resources

- **[Big-O Cheat Sheet](https://www.bigocheatsheet.com/)**: Visual complexity reference
- **[VisuAlgo](https://visualgo.net/)**: Algorithm visualizations (excellent for understanding)
- **[LeetCode](https://leetcode.com/)**: Practice problems with PHP support
- **[HackerRank](https://www.hackerrank.com/)**: Additional algorithm challenges

### PHP Resources

- **[PHP Manual](https://www.php.net/manual/en/)**: Official language reference
- **[PHP: The Right Way](https://phptherightway.com/)**: Modern PHP best practices
- **[PHP Internals Book](https://www.phpinternalsbook.com/)**: Deep dive into PHP implementation

### Books (Recommended Reading)

- **"Introduction to Algorithms"** by Cormen, Leiserson, Rivest, Stein (CLRS) — The definitive algorithms textbook
- **"Grokking Algorithms"** by Aditya Bhargava — Visual, beginner-friendly introduction
- **"The Algorithm Design Manual"** by Steven Skiena — Practical focus with real-world examples

### Related Code with PHP Series

- **[PHP Basics](/series/php-basics/)** — Master PHP fundamentals first
- **[AI/ML for PHP Developers](/series/ai-ml-php-developers/)** — Apply algorithms to machine learning
- **[Python to Laravel](/series/python-developers-love-php-laravel/)** — Compare algorithmic approaches across languages

---

::: tip Ready to Start?
Head to [Chapter 00: Quick Start Guide](/series/php-algorithms/chapters/00-quick-start-guide) for a 5-minute overview, or begin comprehensive learning with [Chapter 01: Algorithm Complexity & Big O Notation](/series/php-algorithms/chapters/01-algorithm-complexity-big-o-notation)!
:::

---

## Continue Your Learning

Master other aspects of modern PHP development:

**→ [PHP Basics](/series/php-basics/)** — Master PHP fundamentals from scratch  
**→ [AI/ML for PHP Developers](/series/ai-ml-php-developers/)** — Apply algorithmic thinking to machine learning  
**→ [Build a CRM with Laravel 12](/series/build-crm-laravel-12/)** — Apply algorithms in production applications

<style>
:root {
  --primary-teal: #0d9488;
  --primary-teal-dark: #0f766e;
  --algo-blue: #3b82f6;
  --algo-indigo: #6366f1;
  --php-amber: #f59e0b;
  --php-orange: #ea580c;
  --neutral-gray: #64748b;
  --bg-light: #f8fafc;
}

/* Chapter card enhancements */
div[style*="display: flex"][style*="align-items: flex-start"] {
  transition: all 0.3s ease;
  padding: 1rem;
  border-radius: 8px;
  border-left: 4px solid var(--algo-blue);
}

div[style*="display: flex"][style*="align-items: flex-start"]:hover {
  background: var(--bg-light);
  transform: translateX(4px);
  box-shadow: 0 2px 12px rgba(59, 130, 246, 0.15);
  border-left-color: var(--algo-indigo);
}

/* Image styling */
div[style*="display: flex"] img[style*="width: 180px"] {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

div[style*="display: flex"]:hover img[style*="width: 180px"] {
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

/* Link styling */
div[style*="display: flex"] h4 a {
  color: var(--algo-blue);
  transition: color 0.2s ease;
}

div[style*="display: flex"] h4 a:hover {
  color: var(--algo-indigo);
}
</style>
