brain

tamnd's digital brain — notes, problems, research

43815 notes

5.1 Hash Tables

A data structure that supports fast insertion, lookup, and deletion by mapping keys to bucket positions via a hash function.

algorithmshashingdata-structureshash-tables
5.5 Rehashing

Rebuild a hash table's bucket array after resizing so that every stored key satisfies the placement invariant for the new capacity.

algorithmshashingrehashingresizing
5.2 Hash Functions

Design and evaluate hash functions that distribute keys uniformly across buckets while remaining fast to compute.

algorithmshashinghash-functionsdesign
4.4 Congruence and Contextual Rewriting

Equality becomes useful when it propagates through larger expressions.

leanproof-assistanttype-theoryfunctional-programming
4.12 Rewriting Under Binders

Rewriting becomes more subtle when the target term appears inside a binder.

leanproof-assistanttype-theoryfunctional-programming
4.9 Rewriting with Hypotheses

In most proofs, equalities come from the local context.

leanproof-assistanttype-theoryfunctional-programming
4.7 Controlling the `simp` Set

The behavior of `simp` depends entirely on the set of rewrite rules it uses.

leanproof-assistanttype-theoryfunctional-programming
4.3 Reflexivity, Symmetry, and Transitivity

Propositional equality in Lean is generated from a small set of core operations.

leanproof-assistanttype-theoryfunctional-programming
4.2 Propositional Equality

Propositional equality is the explicit notion of equality in Lean.

leanproof-assistanttype-theoryfunctional-programming
4.14 Dependent Rewriting and Transport

When types depend on values, rewriting affects both terms and their types.

leanproof-assistanttype-theoryfunctional-programming
4.11 Chained Rewriting and `calc`

Complex equalities are rarely achieved in a single step.

leanproof-assistanttype-theoryfunctional-programming
4.6 Simplification with `simp`

The tactic `simp` performs normalization by repeated rewriting using a curated set of lemmas.

leanproof-assistanttype-theoryfunctional-programming
4.5 Directed Rewriting with `rw`

Rewriting is the primary way to apply propositional equalities in Lean.

leanproof-assistanttype-theoryfunctional-programming
4.18 Rewriting of Functions and Extensionality

Equality between functions requires a different treatment than equality between values.

leanproof-assistanttype-theoryfunctional-programming
4.8 Case Analysis and Rewriting

Case analysis splits a goal according to the structure of a value.

leanproof-assistanttype-theoryfunctional-programming
4.15 Avoiding Rewrite Loops and Nontermination

Rewriting systems can diverge if rules are poorly oriented or interact cyclically.

leanproof-assistanttype-theoryfunctional-programming
4.17 Rewriting in Structures and Records

Structures package multiple fields into a single value.

leanproof-assistanttype-theoryfunctional-programming
4.10 Rewriting with Lemmas

Lemmas provide reusable equalities that drive most rewriting.

leanproof-assistanttype-theoryfunctional-programming
4.16 Rewriting with Equivalences

Equalities are often too strict.

leanproof-assistanttype-theoryfunctional-programming
4.13 Substitution and `subst`

Substitution is the direct elimination of equalities from the context.

leanproof-assistanttype-theoryfunctional-programming
4.1 Definitional Equality

Definitional equality is the built-in notion of equality used by the kernel of Lean.

leanproof-assistanttype-theoryfunctional-programming
4.25 Common Pitfalls and Debugging

Rewriting failures in Lean usually come from a small set of recurring issues.

leanproof-assistanttype-theoryfunctional-programming
4.23 Rewriting in Goals vs Hypotheses

Rewriting can target either the goal or the local context.

leanproof-assistanttype-theoryfunctional-programming
4.22 Rewriting with `conv`

The `conv` tactic provides fine-grained control over rewriting.

leanproof-assistanttype-theoryfunctional-programming
4.19 Proof Irrelevance and Equality of Proofs

In Lean, propositions live in `Prop`, a universe where proof irrelevance holds.

leanproof-assistanttype-theoryfunctional-programming
4.24 Rewriting Strategies and Heuristics

Rewriting is most effective when guided by a small set of consistent strategies.

leanproof-assistanttype-theoryfunctional-programming
4.21 Rewriting in Pattern Matching

Pattern matching performs case analysis by selecting a branch based on the shape of a value.

leanproof-assistanttype-theoryfunctional-programming
4.20 Decidable Equality and Boolean Bridges

Reasoning often alternates between propositional equality `a = b` and boolean equality `a == b`.

leanproof-assistanttype-theoryfunctional-programming
1.25 Common Failure Modes

Even when the algorithmic idea is correct, implementations fail in predictable ways.

algorithmscomputer-sciencecomplexityfoundations
1.20 Implementation Discipline

Implementation discipline means translating an algorithm into code without changing its meaning accidentally.

algorithmscomputer-sciencecomplexityfoundations
1.24 Benchmarking

Benchmarking measures how an implementation behaves on real inputs and real hardware.

algorithmscomputer-sciencecomplexityfoundations
1.21 Data Representation

Data representation is the choice of concrete form used to store the objects in a problem.

algorithmscomputer-sciencecomplexityfoundations
1.23 Stability and Determinism

Stability and determinism describe how predictably an algorithm behaves when there are ties, repeated values, or multiple valid answers.

algorithmscomputer-sciencecomplexityfoundations
1.22 Numerical Limits

Algorithms are usually described with mathematical integers and real numbers.

algorithmscomputer-sciencecomplexityfoundations
1.15 Dynamic Programming

Dynamic programming solves problems by storing answers to subproblems and reusing them.

algorithmscomputer-sciencecomplexityfoundationsdynamic-programming
1.18 Reductions

A reduction transforms one problem into another problem.

algorithmscomputer-sciencecomplexityfoundations
1.16 Randomization

Randomized algorithms use random choices during execution.

algorithmscomputer-sciencecomplexityfoundationsrandomized-algorithms
1.17 Amortized Analysis

Amortized analysis studies the average cost of operations over a sequence, even when individual operations are sometimes expensive.

algorithmscomputer-sciencecomplexityfoundations
1.19 Pseudocode Style

Pseudocode is a bridge between the problem statement and an implementation.

algorithmscomputer-sciencecomplexityfoundations
1.11 Testing Algorithms

Testing does not prove an algorithm correct, but it exposes mistakes in specifications, invariants, edge cases, and implementation details.

algorithmscomputer-sciencecomplexityfoundations
1.13 Greedy Choices

A greedy algorithm builds a solution by making one locally best choice at a time.

algorithmscomputer-sciencecomplexityfoundationsgreedy
1.14 Divide and Conquer

Divide and conquer solves a problem by splitting it into smaller subproblems, solving those subproblems, and combining their answers.

algorithmscomputer-sciencecomplexityfoundationsdivide-and-conquer
1.12 Brute Force Baselines

A brute force baseline is the simplest correct algorithm you can write from the problem statement.

algorithmscomputer-sciencecomplexityfoundations
1.10 Edge Cases

Edge cases are valid inputs that sit at the boundary of the specification.

algorithmscomputer-sciencecomplexityfoundations
1.9 Lower Bounds

A lower bound states that every algorithm for a problem must perform at least a certain amount of work in some model of computation.

algorithmscomputer-sciencecomplexityfoundations
1.7 Space Complexity

Space complexity measures how much memory an algorithm uses as a function of input size.

algorithmscomputer-sciencecomplexityfoundations
1.8 Big O Notation

Big O notation provides a formal way to describe how a function grows.

algorithmscomputer-sciencecomplexityfoundations
1.6 Time Complexity

Time complexity describes how the running time of an algorithm grows as the input size grows.

algorithmscomputer-sciencecomplexityfoundations
1.5 Recursion Invariants

Recursive algorithms replace loop structure with self-reference.

algorithmscomputer-sciencecomplexityfoundationsrecursion
1.2 Input and Output Models

An algorithm does not operate on an abstract idea of data.

algorithmscomputer-sciencecomplexityfoundations
1.4 Loop Invariants

Loop invariants are the primary tool for reasoning about iterative algorithms.

algorithmscomputer-sciencecomplexityfoundationscorrectness
1.3 Correctness Arguments

A correctness argument explains why an algorithm returns an acceptable output for every valid input.

algorithmscomputer-sciencecomplexityfoundations
1.1 Problem Statements

An algorithm begins with a precise statement of the problem.

algorithmscomputer-sciencecomplexityfoundations
3.25 Case Studies

This section combines multiple patterns from the chapter into complete, end-to-end linked list algorithms.

algorithmscomputer-sciencedata-structureslinked-lists
3.24 Complexity Analysis

Linked list algorithms are dominated by pointer traversal and constant-time link updates.

algorithmscomputer-sciencedata-structureslinked-listscomplexity
3.15 Skip Lists

A skip list augments a sorted linked list with multiple levels of forward pointers.

algorithmscomputer-sciencedata-structureslinked-lists
3.23 Testing Pointer Code

Pointer code should be tested by checking structure, not only values.

algorithmscomputer-sciencedata-structureslinked-lists
3.22 Edge Cases

Edge cases are inputs that sit near the boundary of an algorithm's assumptions.

algorithmscomputer-sciencedata-structureslinked-lists
3.12 Dummy Heads (Dummy Nodes)

A dummy head is a fixed node placed before the real head of a singly linked list.

algorithmscomputer-sciencedata-structureslinked-lists
3.20 Queue via List

A queue is a first-in, first-out structure.

algorithmscomputer-sciencedata-structureslinked-lists
3.16 Intrusive Lists

An intrusive list stores the linkage fields inside the objects being linked.

algorithmscomputer-sciencedata-structureslinked-lists
3.17 Memory Ownership

Memory ownership describes which part of a program is responsible for creating, linking, unlinking, and destroying a node.

algorithmscomputer-sciencedata-structureslinked-lists
3.19 Stack via List

A stack is a last-in, first-out (LIFO) structure.

algorithmscomputer-sciencedata-structureslinked-lists
3.11 Insertion Patterns

Insertion adds nodes into a linked list by creating new links while preserving reachability of all existing nodes.

algorithmscomputer-sciencedata-structureslinked-lists
3.18 Iterators

An iterator is an object or procedure that visits the nodes of a linked list one at a time.

algorithmscomputer-sciencedata-structureslinked-lists
3.14 Persistent Lists

A persistent list is a list that preserves older versions after an update.

algorithmscomputer-sciencedata-structureslinked-lists
3.21 LRU Cache Structure

An LRU cache stores a fixed number of key-value entries and removes the least recently used entry when capacity is exceeded.

algorithmscomputer-sciencedata-structureslinked-lists
3.13 Pointer Aliasing

Pointer aliasing occurs when two or more references point to the same node.

algorithmscomputer-sciencedata-structureslinked-lists
3.10 Deletion Patterns

Deletion removes one or more nodes from a linked list by changing links around them.

algorithmscomputer-sciencedata-structureslinked-lists
3.4 Reversal

Reversal transforms a linked list so that the direction of all edges is flipped.

algorithmscomputer-sciencedata-structureslinked-lists
3.5 Cycle Detection

A cycle exists in a linked list when some node’s `next` pointer eventually leads back to a previously visited node.

algorithmscomputer-sciencedata-structureslinked-lists
3.8 Split Patterns

Splitting a linked list means cutting one list into two or more lists while preserving the original nodes.

algorithmscomputer-sciencedata-structureslinked-lists
3.1 Singly Linked Lists

A singly linked list is a sequence of nodes where each node stores a value and a reference to the next node.

algorithmscomputer-sciencedata-structureslinked-lists
3.6 Fast and Slow Pointers

Fast and slow pointers are two references that traverse the same linked structure at different speeds.

algorithmscomputer-sciencedata-structureslinked-lists
3.7 Merge Two Sorted Lists

Merging combines two sorted singly linked lists into one sorted list by relinking nodes.

algorithmscomputer-sciencedata-structureslinked-listssorting
3.2 Doubly Linked Lists

A doubly linked list is a sequence of nodes where each node stores a value, a reference to the next node, and a reference to the previous node.

algorithmscomputer-sciencedata-structureslinked-lists
3.3 Sentinel Nodes

A sentinel node is an artificial node placed at the boundary of a linked list.

algorithmscomputer-sciencedata-structureslinked-lists
3.9 Merge Patterns

Merging is a family of constructions that combine multiple linked lists into one or more output lists while preserving structural invariants.

algorithmscomputer-sciencedata-structureslinked-lists
2.25 Boundary Conditions

Boundary conditions define the valid domain of indices, ranges, and states in an algorithm.

algorithmscomputer-sciencearraysstrings
2.23 Flood Fill

Flood fill explores a connected region in a grid starting from a seed cell and marks or transforms all cells that belong to the same region.

algorithmscomputer-sciencearraysstrings
2.22 Spiral Traversal

Spiral traversal visits a matrix layer by layer, moving right across the top row, down the right column, left across the bottom row, and up the left column,...

algorithmscomputer-sciencearraysstrings
2.24 Common Patterns

Array and string problems often look different on the surface, but many reduce to a small number of reusable patterns.

algorithmscomputer-sciencearraysstrings
2.21 Matrix Traversal

Matrix traversal processes a two-dimensional array in a defined order.

algorithmscomputer-sciencearraysstrings
2.19 Parsing Expressions

Parsing expressions converts a sequence of tokens into a structured form that reflects operator precedence and associativity.

algorithmscomputer-sciencearraysstrings
2.20 Tries

A trie is a tree structure for storing a set of strings so that common prefixes are shared.

algorithmscomputer-sciencearraysstrings
2.17 Rolling Hashes

Rolling hashes assign numeric fingerprints to substrings so that many substring comparisons can be done quickly.

algorithmscomputer-sciencearraysstringshashing
2.18 String Comparison

String comparison determines the ordering or equality of two strings.

algorithmscomputer-sciencearraysstrings
2.13 Palindromes

A palindrome is a sequence that reads the same forward and backward.

algorithmscomputer-sciencearraysstrings
2.14 Anagrams

Anagrams are strings or sequences that contain the same elements with the same multiplicities, possibly in different order.

algorithmscomputer-sciencearraysstrings
2.12 Substring Search

Substring search locates occurrences of a pattern `p` inside a text `s`.

algorithmscomputer-sciencearraysstrings
2.16 Run-Length Encoding

Run-Length Encoding (RLE) compresses sequences by replacing consecutive equal values with a pair `(value, count)`.

algorithmscomputer-sciencearraysstrings
2.15 Frequency Tables

A frequency table records how many times each value appears in an array, string, or stream.

algorithmscomputer-sciencearraysstrings
2.9 Deduplication

Deduplication removes repeated values while preserving a chosen notion of identity and, optionally, order.

algorithmscomputer-sciencearraysstrings
2.6 Partitioning

Partitioning rearranges an array so that elements are grouped by a predicate.

algorithmscomputer-sciencearraysstrings
2.8 In-Place Modification

In-place modification changes an array without allocating another array of the same size.

algorithmscomputer-sciencearraysstrings
2.10 String Scanning

String scanning is the basic operation behind parsing, tokenization, validation, search, and text normalization.

algorithmscomputer-sciencearraysstrings
2.7 Rotation

Array rotation moves elements by a fixed offset while preserving their relative circular order.

algorithmscomputer-sciencearraysstrings
2.11 Tokenization

Tokenization converts a string into a sequence of meaningful units called tokens.

algorithmscomputer-sciencearraysstrings
2.4 Two Pointers

The two pointers technique uses two indices that move through an array or string in a controlled way.

algorithmscomputer-sciencearraysstrings
2.5 Sliding Windows

Sliding windows maintain a contiguous subarray `[l, r)` while both endpoints move forward.

algorithmscomputer-sciencearraysstrings