Algorithms for Competitive ProgrammingThe goal of this project is to translate the wonderful resource http://e-maxx.ru/algo which provides descriptions of many algorithms and data structures especially popular in field of competitive programming. Moreover we want to improve the collected knowledge by extending the articles and adding new articles to the collection.https://cp-algorithms.com/ https://github.com/cp-algorithms/cp-algorithmsen Mon, 29 Dec 2025 19:18:53 -0000 Mon, 29 Dec 2025 19:18:53 -0000 1440 MkDocs RSS plugin - v1.17.7 None Algorithms for Competitive Programming https://cp-algorithms.com/ Finding Power of Factorial Divisor <h1>Finding Power of Factorial Divisor</h1> <p>You are given two numbers $n$ and $k$. Find the largest integer $x$ such that $k^x$ divides $n!$.</p> <h2>Prime $k$ {data-t...</h2> https://cp-algorithms.com/algebra/factorial-divisors.html Mon, 29 Dec 2025 17:12:09 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/algebra/factorial-divisors.html Finding Connected Components <h1>Search for connected components in a graph</h1> <p>Given an undirected graph $G$ with $n$ nodes and $m$ edges. We are required to find in it all the connected com...</p> https://cp-algorithms.com/graph/search-for-connected-components.html Sun, 28 Dec 2025 14:42:11 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/graph/search-for-connected-components.html Euler's totient function <h1>Euler's totient function</h1> <p>Euler's totient function, also known as <strong>phi-function</strong> $\phi (n)$, counts the number of integers between 1 and $n$ inclusive, w...</p> https://cp-algorithms.com/algebra/phi-function.html Sun, 28 Dec 2025 13:07:53 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/algebra/phi-function.html Convex hull construction <h1>Convex Hull construction</h1> <p>In this article we will discuss the problem of constructing a convex hull from a set of points.</p> <p>Consider $N$ points given on a p...</p> https://cp-algorithms.com/geometry/convex-hull.html Fri, 26 Dec 2025 10:25:54 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/geometry/convex-hull.html Strongly Connected Components and Condensation Graph <h1>Strongly connected components and the condensation graph</h1> <h2>Definitions</h2> <p>Let $G=(V,E)$ be a directed graph with vertices $V$ and edges $E \subseteq V \time...</p> https://cp-algorithms.com/graph/strongly-connected-components.html Fri, 26 Dec 2025 00:31:37 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/graph/strongly-connected-components.html Segment Tree <h1>Segment Tree</h1> <p>A Segment Tree is a data structure that stores information about array intervals as a tree. This allows answering range queries over an array...</p> https://cp-algorithms.com/data_structures/segment_tree.html Fri, 19 Dec 2025 07:16:42 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/data_structures/segment_tree.html Disjoint Set Union <h1>Disjoint Set Union</h1> <p>This article discusses the data structure <strong>Disjoint Set Union</strong> or <strong>DSU</strong>. Often it is also called <strong>Union Find</strong> because of its two ...</p> https://cp-algorithms.com/data_structures/disjoint_set_union.html Mon, 15 Dec 2025 01:10:23 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/data_structures/disjoint_set_union.html Gauss & System of Linear Equations <h1>Gauss method for solving system of linear equations</h1> <p>Given a system of $n$ linear algebraic equations (SLAE) with $m$ unknowns. You are asked to solve the ...</p> https://cp-algorithms.com/linear_algebra/linear-system-gauss.html Wed, 10 Dec 2025 11:02:10 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/linear_algebra/linear-system-gauss.html Basic Geometry <h1>Basic Geometry</h1> <p>In this article we will consider basic operations on points in Euclidean space which maintains the foundation of the whole analytical geome...</p> https://cp-algorithms.com/geometry/basic-geometry.html Tue, 09 Dec 2025 13:20:18 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/geometry/basic-geometry.html Binary Exponentiation <h1>Binary Exponentiation</h1> <p>Binary exponentiation (also known as exponentiation by squaring) is a trick which allows to calculate $a^n$ using only $O(\log n)$ m...</p> https://cp-algorithms.com/algebra/binary-exp.html Sat, 29 Nov 2025 17:05:50 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/algebra/binary-exp.html Finding Bridges Online <h1>Finding Bridges Online</h1> <p>We are given an undirected graph. A bridge is an edge whose removal makes the graph disconnected (or, more precisely, increases the...</p> https://cp-algorithms.com/graph/bridge-searching-online.html Sun, 23 Nov 2025 17:50:05 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/graph/bridge-searching-online.html Heavy-light decomposition <h1>Heavy-light decomposition</h1> <p><strong>Heavy-light decomposition</strong> is a fairly general technique that allows us to effectively solve many problems that come down to ...</p> https://cp-algorithms.com/graph/hld.html Wed, 19 Nov 2025 12:44:51 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/graph/hld.html 2-SAT <h1>2-SAT</h1> <p>SAT (Boolean satisfiability problem) is the problem of assigning Boolean values to variables to satisfy a given Boolean formula. The Boolean formul...</p> https://cp-algorithms.com/graph/2SAT.html Thu, 06 Nov 2025 12:07:11 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/graph/2SAT.html Eulerian Path <h1>Finding the Eulerian path in $O(M)$</h1> <p>A Eulerian path is a path in a graph that passes through all of its edges exactly once. A Eulerian cycle is a Eulerian...</p> https://cp-algorithms.com/graph/euler_path.html Mon, 03 Nov 2025 22:39:11 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/graph/euler_path.html Garner's Algorithm <h1>Garner's algorithm</h1> <p>A consequence of the <a href="chinese-remainder-theorem.md">Chinese Remainder Theorem</a> is, that we can represent big numbers using an array of ...</p> https://cp-algorithms.com/algebra/garners-algorithm.html Wed, 29 Oct 2025 17:23:37 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/algebra/garners-algorithm.html Linear Diophantine Equations <h1>Linear Diophantine Equation</h1> <p>A Linear Diophantine Equation (in two variables) is an equation of the general form:</p> <p>$$ax + by = c$$</p> <p>where $a$, $b$, $c$ are...</p> https://cp-algorithms.com/algebra/linear-diophantine-equation.html Wed, 29 Oct 2025 17:22:34 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/algebra/linear-diophantine-equation.html Floyd-Warshall - finding all shortest paths <h1>Floyd-Warshall Algorithm</h1> <p>Given a directed or an undirected weighted graph $G$ with $n$ vertices. The task is to find the length of the shortest path $d_{i...</p> https://cp-algorithms.com/graph/all-pair-shortest-path-floyd-warshall.html Sat, 25 Oct 2025 00:41:59 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/graph/all-pair-shortest-path-floyd-warshall.html Extended Euclidean Algorithm <h1>Extended Euclidean Algorithm</h1> <p>While the <a href="euclid-algorithm.md">Euclidean algorithm</a> calculates only the greatest common divisor (GCD) of two integers $a$ an...</p> https://cp-algorithms.com/algebra/extended-euclid-algorithm.html Sun, 12 Oct 2025 14:21:08 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/algebra/extended-euclid-algorithm.html Finding the nearest pair of points <h1>Finding the nearest pair of points</h1> <h2>Problem statement</h2> <p>Given $n$ points on the plane. Each point $p_i$ is defined by its coordinates $(x_i,y_i)$. It is ...</p> https://cp-algorithms.com/geometry/nearest_points.html Tue, 07 Oct 2025 21:40:34 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/geometry/nearest_points.html Sparse Table <h1>Sparse Table</h1> <p>Sparse Table is a data structure, that allows answering range queries. It can answer most range queries in $O(\log n)$, but its true power is...</p> https://cp-algorithms.com/data_structures/sparse-table.html Fri, 26 Sep 2025 04:55:43 +0000 Algorithms for Competitive Programminghttps://cp-algorithms.com/data_structures/sparse-table.html