DSA Lab

Understand algorithms. Don't just memorize them.

Data structures and algorithms from first principles, for developers who already program: memory, complexity and the collections you use every day, then the structures, algorithms and patterns behind interview problems.

Every concept in 4 languages

  • C#
  • Python
  • Java
  • C++

Binary search, two steps

Step 1: the middle is 12, smaller than 23, so drop the left half

  • 2
  • 5
  • 8
  • 12
  • 16
  • 23
  • 38
  • 56

Step 2: the middle is 23, found

  • 2
  • 5
  • 8
  • 12
  • 16
  • 23
  • 38
  • 56
Illustration. The visualizers replay the real algorithm on your own input, step by step.

Watch an append resize the buffer

A dynamic array with capacity 2 receives a third element: a new buffer is allocated, both elements are copied, and the old buffer is dropped. Step through it, switch languages, and watch the highlighted lines follow.

old buffer, capacity 273copy both, then appendnew buffer, capacity 4739

preview · the interactive demo loads here

Preview

Initial state: an empty array whose buffer has capacity 2. The third append allocates a new buffer, copies both elements and drops the old one.

Step through it, switch languages and watch the highlighted lines follow. Without JavaScript, the dynamic arrays lesson explains the same thing in text and code.

C#PythonJavaC++
namespace Bekadan.Dsa.Examples.DynamicArrays;
 
/// <summary>
/// A growable array backed by a fixed-size buffer that doubles when full.
/// A teaching model of <see cref="List{T}"/>, which uses Array.Copy and starts
/// at capacity 4, but has the same costs.
/// </summary>
public sealed class DynamicArray<T>
{
    private T[] _items;
    private int _count;
 
    public DynamicArray(int initialCapacity = 0)
    {
        ArgumentOutOfRangeException.ThrowIfNegative(initialCapacity);
        _items = new T[initialCapacity];
    }
 
    public int Count => _count;
 
    public int Capacity => _items.Length;
 
    public T this[int index]
    {
        get
        {
            if (index < 0 || index >= _count)
                throw new ArgumentOutOfRangeException(nameof(index));
            return _items[index];
        }
        set
        {
            if (index < 0 || index >= _count)
                throw new ArgumentOutOfRangeException(nameof(index));
            _items[index] = value;
        }
    }
 
    public void Add(T item)
    {
        if (_count == _items.Length)
            Grow();
        _items[_count] = item;
        _count++;
    }
 
    public void Insert(int index, T item)
    {
        if (index < 0 || index > _count)
            throw new ArgumentOutOfRangeException(nameof(index));
        if (_count == _items.Length)
            Grow();
        for (int i = _count; i > index; i--)
            _items[i] = _items[i - 1];
        _items[index] = item;
        _count++;
    }
 
    public T RemoveAt(int index)
    {
        if (index < 0 || index >= _count)
            throw new ArgumentOutOfRangeException(nameof(index));
        T removed = _items[index];
        for (int i = index; i < _count - 1; i++)
            _items[i] = _items[i + 1];
        _items[_count - 1] = default!; // drop the leftover reference for the GC
        _count--;
        return removed;
    }
 
    private void Grow()
    {
        int newCapacity = _items.Length == 0 ? 1 : _items.Length * 2;
        var newItems = new T[newCapacity];
        for (int i = 0; i < _count; i++)
            newItems[i] = _items[i];
        _items = newItems; // the old array becomes garbage
    }
}

Tested on .NET 10 (SDK 10.0.403), C# 14 · examples/csharp/Bekadan.Dsa.Examples/DynamicArrays/DynamicArray.cs

Variables

size
0
capacity
2

Metrics so far

Element writes, reads, resize copies, shifts, allocations and operations, counted as the steps run.

Cost per operation (element writes)

Costs appear here as operations finish.

Problem-solving paths

Ordered routes from fundamentals to interview preparation. Every step says why it is there.

All 9 paths
  • Fundamentals

    From precise problem statements and Big O to arrays, hashing, recursion, searching, sorting and trees: the base every later topic builds on.

    14 steps

  • Complete DSA

    All 35 curriculum modules in teaching order, grouped into stages, with the patterns, problems and visualizers that go with each stage.

    13 steps

  • Interview preparation

    The patterns that coding interviews keep returning to, in an order where each one reuses the last, with solved problems to practise every step.

    15 steps

  • DSA for backend engineers

    The structures behind caches, job queues, schedulers, rate limiters, database indexes and dependency graphs, and what each operation really costs.

    12 steps

  • Competitive programming

    Read constraints, pick the algorithm that fits them, and know the techniques contests rely on: bits, math, prefix sums, binary search on answer, graphs and DP.

    12 steps

Explore the lab

  • Learning paths

    Ordered routes: fundamentals, complete DSA, interviews, backend, competitive programming and per-language collections.

    9 paths

  • Data structures

    Operations, invariants and costs, with a visualizer and four tested implementations for each.

    12 structures

  • Algorithms

    Searching, sorting, graphs, strings, greedy, divide and conquer and dynamic programming.

    31 algorithms

  • Playground

    Run any visualizer on your own input and step forwards and backwards through the real algorithm.

    42 visualizers

  • Memory Lab

    Values and references, stack and heap, locality, reallocation and reachability, per language.

    5 simulations

  • Compare

    Two algorithms on the same input, with every metric defined the same way for both. No fabricated benchmarks.

    3 comparisons

  • Solved problems

    Original problems with hints, a correctness argument, four tested implementations and a walkthrough.

    50 problems

  • Collections

    What List<T>, dict, HashMap and std::vector actually cost, operation by operation.

    20 references

  • Patterns

    How to recognise two pointers, sliding window, BFS, DP and more, with templates and pitfalls.

    16 patterns

  • Complexity

    A Big O explorer and worked exercises with exact operation counts.

    30 exercises

  • Cheatsheets

    Printable references for Big O, collections, sorting, patterns and language gotchas.

    5 sheets

  • Glossary

    Short definitions with links to the lessons and visualizers that show them.

    121 terms

  • Interview plans

    Sequences of problems and patterns for interview preparation. No timers, no scores.

    two- and four-week

Available lessons

Each one has a 3D visualizer you can step through, tested code in C#, Python, Java and C++, and worked practice.

How the lab teaches

  • Operations before implementations

    Start from what List<T>, list, ArrayList and std::vector do and cost, then build the structure underneath.

  • Every step is real

    Visualizations replay a deterministic trace of the actual algorithm. Step backwards, change the input, and the same seed gives the same run.

  • Four languages, one idea

    C#, Python, Java and C++ side by side, each tested against the same cases, with the differences between runtimes spelled out.

  • Learning, not judging

    No online judge, no leaderboard and no generated answers: explanations, worked solutions and simulations you can drive.