brain

tamnd's digital brain — notes, problems, research

41806 notes

11.24 Common Bugs

Minimum spanning tree code often fails for reasons that are easy to miss in clean textbook examples.

algorithmsgraphsspanning-trees
11.4 Kruskal's Algorithm

Given a connected weighted undirected graph, find a spanning tree whose total edge weight is minimum.

algorithmsgraphsspanning-trees
11.25 Case Study: Building a Production-Quality MST Service

Throughout this chapter, we have studied minimum spanning trees from multiple perspectives: * Graph theory * Greedy algorithms * Union-find

algorithmsgraphsspanning-trees
11.13 Second-Best Spanning Tree

A minimum spanning tree gives the cheapest way to connect all vertices.

algorithmsgraphsspanning-trees
11.11 Dynamic Connectivity Overview

Offline connectivity works well when edges are fixed, or when all updates can be processed in a convenient order.

algorithmsgraphsspanning-trees
11.23 Choosing the Right MST Algorithm

By this point, you have seen three major minimum spanning tree algorithms: ```text Kruskal Prim

algorithmsgraphsspanning-trees
11.2 Cut Property

Minimum spanning tree algorithms repeatedly make local decisions.

algorithmsgraphsspanning-trees
11.5 Prim's Algorithm

Kruskal's algorithm builds a minimum spanning tree by selecting edges globally.

algorithmsgraphsspanning-trees
11.14 Clustering

You have a set of objects and pairwise distances between them.

algorithmsgraphsspanning-trees
11.20 Complexity Analysis

Minimum spanning tree algorithms are easy to state, but their performance depends heavily on representation and data structure choices.

algorithmsgraphsspanning-trees
11.21 Implementation Patterns

After studying cut properties, union-find, Kruskal, Prim, Borůvka, clustering, network design, and complexity analysis, a practical question remains: > How should MST algorithms actually be implemente...

algorithmsgraphsspanning-trees
11.7 Union-Find

Many graph algorithms repeatedly ask the same question: > Do these two vertices already belong to the same connected component?

algorithmsgraphsspanning-trees
11.18 Parallel and Distributed MST Algorithms

The classical MST algorithms were designed for a single machine processing a graph stored in local memory.

algorithmsgraphsspanning-trees
11.12 Minimum Bottleneck Spanning Trees

Minimum spanning trees minimize the **total weight** of selected edges.

algorithmsgraphsspanning-trees
11.16 Sparse Graph Handling

Minimum spanning tree algorithms are usually described in terms of `V` vertices and `E` edges.

algorithmsgraphsspanning-trees
11.3 Cycle Property

The cut property identifies edges that can safely be added to a minimum spanning tree.

algorithmsgraphsspanning-trees
10.3 Solving Nonnegative Weighted Shortest Paths with Dijkstra's Algorithm

Breadth-first search works because every edge contributes the same cost.

algorithmsshortest-pathsgraphs
10.11 Accelerating Search with A

Dijkstra's algorithm finds shortest paths by expanding vertices in order of increasing distance from the source.

algorithmsshortest-pathsgraphs
10.10 Solving 0-1 Shortest Path Problems with 0-1 BFS

Between ordinary BFS and Dijkstra lies an interesting class of shortest-path problems.

algorithmsshortest-pathsgraphs
10.19 Modeling State-Space Problems as Shortest Paths

One of the most powerful ideas in algorithm design is that many problems that do not look like graph problems can be transformed into shortest-path problems.

algorithmsshortest-pathsgraphs
10.1 Finding Shortest Paths in Unweighted Graphs with Breadth-First Search

Breadth-first search (BFS) is the simplest shortest path algorithm.

algorithmsshortest-pathsgraphs
10.22 Analyzing Complexity of Shortest-Path Algorithms

Shortest-path algorithms are often chosen by correctness first, then by complexity.

algorithmsshortest-pathsgraphs
10.25 Debugging and Optimizing Shortest-Path Code

Shortest-path code usually fails in predictable ways.

algorithmsshortest-pathsgraphs
10.20 Choosing the Right Shortest-Path Algorithm

This chapter introduced a substantial collection of shortest-path algorithms.

algorithmsshortest-pathsgraphs
10.2 Finding Shortest Paths with BFS

Use BFS when every edge has the same cost.

algorithmsshortest-pathsgraphs
10.18 Solving Shortest Paths on Grids

Many shortest-path problems are not given as explicit graph structures.

algorithmsshortest-pathsgraphs
10.16 Solving Sparse All-Pairs Shortest Paths with Johnson's Algorithm

The shortest-path algorithms studied so far naturally divide into two groups.

algorithmsshortest-pathsgraphs
10.14 Using Distance Labels and Relaxation Correctly

Every shortest-path algorithm in this chapter appears different on the surface.

algorithmsshortest-pathsgraphs
10.5 Detecting Negative Edges with Bellman-Ford

Dijkstra's algorithm depends on a crucial assumption: edge weights must be nonnegative.

algorithmsshortest-pathsgraphs
10.6 Detecting Negative Cycles with Bellman-Ford

In the previous recipe, Bellman-Ford was used to compute shortest paths in graphs that contain negative edge weights.

algorithmsshortest-pathsgraphs
10.17 Finding K Shortest Paths

Most shortest-path algorithms answer a single question: > What is the shortest path from the source to the destination?

algorithmsshortest-pathsgraphs
10.4 Implementing Dijkstra with Priority Queue Variants

The previous recipe used Dijkstra’s algorithm with a binary heap and lazy deletion.

algorithmsshortest-pathsgraphs
10.13 Reconstructing Shortest Paths

Most shortest-path algorithms compute distances.

algorithmsshortest-pathsgraphs
10.24 Testing Shortest-Path Implementations

Shortest-path implementations are prone to subtle errors.

algorithmsshortest-pathsgraphs
10.15 Using Potentials to Reweight Graphs

Negative edge weights complicate shortest-path algorithms.

algorithmsshortest-pathsgraphs
10.9 Computing Multi-Source Shortest Paths

Most shortest-path problems begin with a single source vertex.

algorithmsshortest-pathsgraphs
10.12 Accelerating Searches with Bidirectional Search

Many shortest-path algorithms begin at the source and gradually expand outward until the target is reached.

algorithmsshortest-pathsgraphs
10.21 Proving Correctness of Shortest-Path Algorithms

Shortest-path algorithms are easy to implement incorrectly.

algorithmsshortest-pathsgraphs
10.7 Computing All-Pairs Shortest Paths with Floyd-Warshall

The algorithms covered so far solve the single-source shortest path problem.

algorithmsshortest-pathsgraphs
10.8 Finding Shortest Paths in Directed Acyclic Graphs

Many shortest-path algorithms are designed to handle arbitrary graphs.

algorithmsshortest-pathsgraphs
10.23 Common Shortest-Path Patterns and Interview Problems

Learning shortest-path algorithms is only the first step.

algorithmsshortest-pathsgraphs
9.13 Cycle Detection

You need to determine whether a graph contains a cycle.

algorithmsgraphsgraph-theory
9.20 Graph Coloring Basics

You need to assign labels, colors, or resources to vertices so that adjacent vertices do not conflict.

algorithmsgraphsgraph-theory
9.8 Degree and Connectivity

You need basic measurements that describe the local and global structure of a graph.

algorithmsgraphsgraph-theory
9.12 Topological Sort

You need to arrange tasks in an order that respects dependencies.

algorithmsgraphsgraph-theory
9.1 Graph Models

You need to turn a real problem into a graph before choosing an algorithm.

algorithmsgraphsgraph-theory
9.11 Connected Components

You need to identify independent regions within a graph.

algorithmsgraphsgraph-theory
9.19 Hamiltonian Paths

You need to visit every vertex exactly once.

algorithmsgraphsgraph-theory
9.7 Weighted Graphs

You need to model relationships where connections have different costs.

algorithmsgraphsgraph-theory
9.16 Articulation Points

You need to find vertices whose removal disconnects an undirected graph.

algorithmsgraphsgraph-theory
9.10 Breadth-First Search (BFS)

You need to explore a graph in order of increasing distance from a starting vertex.

algorithmsgraphsgraph-theory
9.17 Bridges

You need to find edges whose removal disconnects a graph.

algorithmsgraphsgraph-theory
9.6 Undirected Graphs

You need to model relationships that are naturally symmetric.

algorithmsgraphsgraph-theory
9.4 Edge Lists

You need a graph representation that is simple to construct, compact to store, and efficient for algorithms that process edges directly.

algorithmsgraphsgraph-theory
9.25 Graph Algorithm Patterns and Interview Strategies

You are given a graph problem and need to quickly identify the correct algorithmic approach.

algorithmsgraphsgraph-theory
9.22 Graph Representation Tradeoffs

You need to choose the right in-memory representation for a graph.

algorithmsgraphsgraph-theory
9.18 Euler Paths

You need to traverse every edge in a graph exactly once.

algorithmsgraphsgraph-theory
9.23 Shortest Path Fundamentals

You need to find the cheapest route between vertices.

algorithmsgraphsgraph-theory
9.15 Strongly Connected Components

You need to identify groups of vertices that are mutually reachable.

algorithmsgraphsgraph-theory
9.9 Depth-First Search (DFS)

You need to explore a graph systematically.

algorithmsgraphsgraph-theory
9.21 Minimum Spanning Trees

You need to connect all vertices in a graph while minimizing total cost.

algorithmsgraphsgraph-theory
9.5 Directed Graphs

You need to model relationships that have direction.

algorithmsgraphsgraph-theory
9.24 Testing Graph Code

You need confidence that a graph algorithm handles real inputs, edge cases, and malformed assumptions correctly.

algorithmsgraphsgraph-theory
9.2 Adjacency Lists

You need a graph representation that supports efficient traversal, scales to large datasets, and works naturally with algorithms such as depth-first search, breadth-first search, topological sorting,...

algorithmsgraphsgraph-theory
9.3 Adjacency Matrices

You need a graph representation that can answer edge-existence queries quickly.

algorithmsgraphsgraph-theory
9.14 Bipartite Graphs

You need to divide vertices into two groups such that every edge connects vertices from different groups.

algorithmsgraphsgraph-theory
8.19 Link-Cut Trees

All previous tree algorithms in this chapter assume that the tree structure is fixed.

algorithmstreesdata-structures
8.3 Breadth-First Search Traversal

Breadth-first search (BFS) visits a tree level by level.

algorithmstreesdata-structures
8.25 Choosing the Right Tree Algorithm

This chapter has introduced a wide range of tree algorithms and data structures.

algorithmstreesdata-structures
8.2 Depth-First Search Traversal

Depth-first search (DFS) is the fundamental traversal technique for trees.

algorithmstreesdata-structures
8.23 Expression Trees

Expression trees represent computations as tree structures.

algorithmstreesdata-structures
8.24 Merkle Trees

Suppose two computers each store a copy of a large dataset.

algorithmstreesdata-structures
8.10 Subtree Queries

Many tree problems ask questions about an entire subtree rather than an individual node.

algorithmstreesdata-structures
8.5 Tree Height

Tree height measures how far a tree extends downward from a node.

algorithmstreesdata-structures
8.8 Binary Lifting

Many tree algorithms repeatedly ask the same question: > What is the ancestor of this node k levels above?

algorithmstreesdata-structures
8.20 Tree Isomorphism

Two trees may look different at first glance yet represent exactly the same structure.

algorithmstreesdata-structures
8.22 Succinct Trees

Most tree representations focus on speed.

algorithmstreesdata-structures
8.13 Segment Trees

Many tree algorithms eventually become range-query problems.

algorithmstreesdata-structures
8.4 Recursion on Trees

Most tree algorithms are recursive, not because recursion is elegant, but because trees are recursive objects.

algorithmstreesdata-structures
8.11 Rerooting Dynamic Programming

Many tree algorithms compute information relative to a fixed root.

algorithmstreesdata-structures
8.6 Tree Diameter

The diameter of a tree is the length of the longest path between any two nodes.

algorithmstreesdata-structures
8.15 Lazy Propagation

Segment Trees provide efficient range queries and point updates.

algorithmstreesdata-structures
8.21 Tree Serialization

A tree in memory is not directly portable.

algorithmstreesdata-structures
8.14 Fenwick Trees

Not every range-query problem requires the full power of a Segment Tree.

algorithmstreesdata-structures
8.1 Tree Representation

Trees are usually introduced with drawings: circles connected by lines, one circle at the top, several below it, then more below those.

algorithmstreesdata-structures
8.7 Lowest Common Ancestor

The Lowest Common Ancestor (LCA) of two nodes is the deepest node that is an ancestor of both.

algorithmstreesdata-structures
8.12 Tries

Many search problems involve prefixes.

algorithmstreesdata-structures
8.16 Persistent Trees

Most data structures answer questions about the present.

algorithmstreesdata-structures
8.18 Centroid Decomposition

Many tree algorithms process information from a fixed root.

algorithmstreesdata-structures
8.9 Euler Tour Technique

Many tree problems become dramatically easier when you stop thinking of the tree as a tree.

algorithmstreesdata-structures
8.17 Heavy-Light Decomposition

Many tree problems ask questions about paths.

algorithmstreesdata-structures
Kvant Math Problem 190

The motion is completely determined by the two lines and the current point.

kvantmathematicsolympiad
Kvant Math Problem 188

Represent the airline network by a simple graph $G$ on $2n$ vertices.

kvantmathematicsolympiad
Kvant Math Problem 186

We seek all integer triples $(x,y,z)$, none equal to $1$, satisfying

kvantmathematicsolympiad
Kvant Math Problem 185

Consider a coat of area $1$ and five patches, each of area at least $\frac{1}{2}$.

kvantmathematicsolympiad
Kvant Math Problem 183

Let the trapezoid have bases of lengths $b$ and $a$, with $a<b$.

kvantmathematicsolympiad
Kvant Math Problem 182

Begin by examining the three-variable inequality

kvantmathematicsolympiad
Kvant Math Problem 180

A strategy can be represented by a decision tree.

kvantmathematicsolympiad
Kvant Math Problem 620

Consider small values of $n$ first.

kvantmathematicsolympiad
Kvant Math Problem 621

Let the circle have center $O$ and radius $r$.

kvantmathematicsolympiad