Data structures and algorithms, visually

Every topic as a short animation you step through, with the running line of code highlighted in C++, Python or C#. Pick a topic to read the idea and the code, then watch it run.

Arrays

Scans, two pointers, windows and prefix sums over contiguous data.

Strings

Character-level versions of the pointer and counting patterns.

Hashing

Trade memory for O(1) lookups with Dictionary and HashSet.

Sorting

The classic sorts, from quadratic to n log n to linear.

Stacks and queues

Last in first out, first in first out, and the monotonic tricks.

Linked lists

Pointer rewiring and the fast and slow runner.

Trees

Binary search trees, the DFS orders, and level order.

Heaps

Priority queues: always know the smallest or largest item.

Graphs

Traversal, shortest paths, ordering and spanning trees.

Backtracking

Try a choice, recurse, undo it, try the next.

Dynamic programming

Solve each subproblem once and reuse the answer.

Bit manipulation

Working directly with the binary form of a number.

C# concepts

How the language and runtime behave: memory, strings, LINQ, async and collections.

Value types and reference typesAssigning a struct copies the data. Assigning a class instance copies only the reference to it.copy: O(size)Boxing and unboxingStoring a value type in an object variable wraps a copy of it in a heap object. Reading it back copies it out again.O(1) plus an allocationPassing by value, ref and outBy default a method gets a copy of the argument. ref and out hand over the caller's variable itself.O(1)String immutability and StringBuilderA string can never be changed after it is created. "Modifying" one always builds a new string.s += x is O(n)Closures and the loop variable trapA lambda captures the variable, not the value it had at that moment. In a for loop that surprises almost everyone once.O(n)LINQ deferred executionA LINQ query is a recipe, not a result. It runs each time you enumerate it, against the data as it is then.runs on enumerationasync and awaitawait does not block the thread. It pauses the method, hands control back to the caller, and resumes when the work finishes.non-blockingHow List<T> growsA List<T> is an array with spare room. When the room runs out it allocates an array twice as big and copies everything across.Add is O(1) amortisedInside a Dictionary: buckets and collisionsA dictionary turns the key into a number, uses that number to choose a bucket, and only searches inside that one bucket.O(1) averagetry, catch and finallyFollow the path through a try block when the code succeeds and when it throws.O(1)Iterators and yield returnA method with yield return produces its values one at a time, pausing between them until the caller asks for the next.O(1) per itemIQueryable vs IEnumerable in EF CoreWith IQueryable, EF Core can send the filter and limit to SQL. After ToList, the same LINQ operators run in memory.depends on query planCancellationToken and async requestsCancellation is a signal the operation must observe. Passing a token to async I/O lets the caller request that work stop.cooperative

OOP concepts

Classes, encapsulation, inheritance, polymorphism and interfaces, shown as running code.

Design patterns

Reusable ways to structure object creation, data access and interchangeable behaviour.

SOLID principles

Five design principles for keeping object-oriented code easier to change and test.