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
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.
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.
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.
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
Cheatsheets
Printable references for Big O, collections, sorting, patterns and language gotchas.
5 sheets
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.
M01 · Algorithmic Thinking
From problem to algorithm: inputs, outputs and constraints
M01 · Algorithmic Thinking
Correctness: loop invariants and edge cases
M02 · Memory Model
Values, references and pointers
M02 · Memory Model
The call stack and the heap
M02 · Memory Model
Contiguous storage, addresses and cache locality
M02 · Memory Model
Reallocation and invalidated references
M02 · Memory Model
Reachability, garbage collection and RAII
M04 · Built-in Collections
Choosing a collection in C#, Python, Java and C++
M04 · Built-in Collections
Iterators, equality and hashing contracts
M04 · Built-in Collections
Sorted collections and priority queues
M05 · Arrays
Array layout and indexing
M05 · Arrays
Traversal and linear search
M05 · Arrays
Insert and delete in a fixed array
M05 · Arrays
Multidimensional and jagged arrays
M06 · Strings
String matching: naive search and Knuth–Morris–Pratt
M07 · Linked Lists
Singly linked lists: nodes, head and tail
M09 · Queues and Deques
Queues: first in, first out in a ring buffer
M10 · Hash Tables and Sets
Hash tables: buckets, chaining and load factor
M10 · Hash Tables and Sets
Open addressing: probing and tombstones
M12 · Searching
Linear search and its preconditions
M12 · Searching
Binary search: halving a sorted range
M12 · Searching
Jump, exponential and interpolation search
M13 · Sorting
Stability and in-place sorting
M13 · Sorting
Bubble, selection and insertion sort
M13 · Sorting
Merge sort: split, merge and the auxiliary buffer
M13 · Sorting
Quicksort and partitioning
M13 · Sorting
What built-in sorts actually do
M14 · Two Pointers
Two pointers: opposite ends and read/write
M15 · Sliding Window
Sliding window: fixed and variable windows
M16 · Prefix Sum and Difference Array
Prefix sums and difference arrays
M17 · Binary Search Patterns
Binary search on the answer: the first true of a monotonic predicate
M19 · Binary Search Trees
Binary search trees: search, insert, delete and the cost of height
M20 · Balanced Trees
AVL trees and rotations, with red-black trees and B-trees
M21 · Heaps and Priority Queues
Heaps and priority queues
M21 · Heaps and Priority Queues
Heap sort
M22 · Tries
Tries: insert, search, prefixes and delete
M23 · Graph Fundamentals
Graph representations: edge list, adjacency matrix and adjacency list
M24 · BFS and DFS
BFS and DFS on graphs: queues, recursion and what each finds
M25 · Topological Sort
Topological sort with Kahn’s algorithm and cycle detection
M26 · Shortest Paths
Dijkstra’s algorithm with a binary heap
M28 · Union Find
Disjoint sets: union by rank and path compression
M27 · Minimum Spanning Trees
Minimum spanning trees: cut and cycle properties, Kruskal and Prim
M29 · Divide and Conquer
Divide and conquer: recurrences, the Master theorem and quickselect
M31 · Backtracking
Backtracking: subsets and permutations on a decision tree
M32 · Dynamic Programming
From recursion to dynamic programming: Fibonacci three ways
M32 · Dynamic Programming
0/1 knapsack: a 2D table and its traceback
M33 · Bit Manipulation
Bits, masks and two’s complement
M34 · Math
Euclid’s algorithm: GCD and LCM
M34 · Math
Primes with the Sieve of Eratosthenes
M35 · Advanced Problem Solving
From constraints to technique
M35 · Advanced Problem Solving
Combining structures: LRU cache, randomized set and running median
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.
The curriculum
35 modules in dependency order. Lessons are published in reviewed batches; 61 are live now and the rest are marked planned.
- M01Algorithmic Thinkinglive
- M02Memory Modellive
- M03Big Olive
- M04Built-in Collectionslive
- M05Arrayslive
- M06Stringslive
- M07Linked Listslive
- M08Stackslive
- M09Queues and Dequeslive
- M10Hash Tables and Setslive
- M11Recursionlive
- M12Searchinglive
- M13Sortinglive
- M14Two Pointerslive
- M15Sliding Windowlive
- M16Prefix Sum and Difference Arraylive
- M17Binary Search Patternslive
- M18Treeslive
- M19Binary Search Treeslive
- M20Balanced Treeslive
- M21Heaps and Priority Queueslive
- M22Trieslive
- M23Graph Fundamentalslive
- M24BFS and DFSlive
- M25Topological Sortlive
- M26Shortest Pathslive
- M28Union Findlive
- M27Minimum Spanning Treeslive
- M29Divide and Conquerlive
- M30Greedylive
- M31Backtrackinglive
- M32Dynamic Programminglive
- M33Bit Manipulationlive
- M34Mathlive
- M35Advanced Problem Solvinglive