All topics
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 Strings Hashing Sorting Stacks and queues Linked lists Trees Heaps Graphs Backtracking Dynamic programming Bit manipulation C# concepts OOP concepts Design patterns SOLID principles
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.
Binary search tree: insert Build a BST one key at a time. Smaller keys go left, larger keys go right. O(h) Binary search tree: search Look up a key by walking down from the root, discarding a whole subtree at every step. O(h) Inorder traversal Left subtree, then the node, then the right subtree. On a BST this yields the keys in sorted order. O(n) Preorder traversal The node first, then its left subtree, then its right subtree. Parents always come before their children. O(n) Postorder traversal Both subtrees first, then the node. Children are always finished before their parent. O(n) Level order traversal (BFS) Visit the tree level by level, left to right, using a queue. O(n) Height of a tree The number of nodes on the longest path from the root down to a leaf, computed bottom-up. O(n) Lowest common ancestor in a BST Find the deepest node that has both given keys beneath it (or is one of them). O(h) 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 types Assigning a struct copies the data. Assigning a class instance copies only the reference to it. copy: O(size) Boxing and unboxing Storing 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 allocation Passing by value, ref and out By default a method gets a copy of the argument. ref and out hand over the caller's variable itself. O(1) String immutability and StringBuilder A 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 trap A 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 execution A LINQ query is a recipe, not a result. It runs each time you enumerate it, against the data as it is then. runs on enumeration async and await await does not block the thread. It pauses the method, hands control back to the caller, and resumes when the work finishes. non-blocking How List<T> grows A 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) amortised Inside a Dictionary: buckets and collisions A dictionary turns the key into a number, uses that number to choose a bucket, and only searches inside that one bucket. O(1) average try, catch and finally Follow the path through a try block when the code succeeds and when it throws. O(1) Iterators and yield return A method with yield return produces its values one at a time, pausing between them until the caller asks for the next. O(1) per item IQueryable vs IEnumerable in EF Core With IQueryable, EF Core can send the filter and limit to SQL. After ToList, the same LINQ operators run in memory. depends on query plan CancellationToken and async requests Cancellation 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.