Sefism is free for learners. We are here to help you grow, one step at a time.Join for free
Sefism.
Guide · OtherFree

Algorithms for Competitive Programming (cp-algorithms)

A free, volunteer-run encyclopedia of algorithms and data structures used in competitive programming, with clear explanations, proofs and C++ implementations for everything from the sieve and binary exponentiation to segment trees, LCA and string algorithms. Started as an English translation of the Russian site e-maxx and has grown well beyond it.

GitHub stars

11.2k (cp-algorithms/cp-algorithms)

GitHub · Sept 2026

Licence

CC BY-SA 4.0

GitHub · Sept 2026

Format

Guide

Topic

Other

Provider

cp-algorithms

Time needed

Reference: read one article when you need it

Level

Intermediate

Access

Free

What cp-algorithms is

Algorithms for Competitive Programming, usually called cp-algorithms, is a website of articles on the algorithms and data structures that come up in programming contests. The project began as a translation of e-maxx.ru, a well-known Russian collection, and its maintainers say they also want to "improve the collected knowledge by extending the articles and adding new articles to the collection." It describes itself as an ad-free, volunteer-run website that is free for everyone, and its source is on GitHub under the CC BY-SA 4.0 licence.

What it covers

The articles are grouped into Algebra (including primes, sieves, modular arithmetic and binary exponentiation), Data Structures (disjoint set union, Fenwick tree, segment tree, sparse table and more), Dynamic Programming, String Processing, Linear Algebra, Combinatorics, Numerical Methods, Geometry, Graphs (BFS, DFS, shortest paths, spanning trees, LCA, flows) and Miscellaneous.

Each article explains the idea, usually proves why it works, gives the complexity and shows a C++ implementation. Many end with a list of practice problems on other judges.

Is it for beginners?

Partly. The articles are precise and sometimes mathematical, so a complete beginner will find them dense. It works best once you know the basics and want to understand one specific technique properly: how a segment tree really works, why the sieve runs in O(n log log n), or how binary lifting finds an LCA. For a first, gentler pass, read the matching chapter in the Competitive Programmer's Handbook or the USACO Guide, then come here for depth.

How to use it well

  • Read the explanation before the code. The code is compact and easier to follow once you know the idea.
  • Write your own version from the explanation, test it on a CSES or Codeforces problem, and only then compare with the article's code.
  • Use the practice problems at the end of an article to check you can apply the technique, not just recognise it.
  • Keep your tested implementations; they become your personal contest library, or your team notebook if you do ICPC.

Free or paid?

Free, with no adverts. The project accepts sponsorship through GitHub for those who want to support it.

Common questions

Is the code allowed in contests? Most platforms allow using code you have prepared or copied from public sources during a contest, but rules differ, so check each platform. The best habit is to understand and retype it rather than paste blindly.

Is it complete? No single site is. It covers the classic toolkit very well; newer tricks often live in contest editorials and blogs.

Best for: contestants past the basics who want a trustworthy, detailed explanation of one algorithm at a time.

algorithmsdata structurescomputer scienceopen source

Ready to start?

Opens on cp-algorithms in a new tab.

Open resource
Link broken or out of date?

Report a problem

With "Algorithms for Competitive Programming (cp-algorithms)". Only Tauseef reads this.

Work with me

Stuck on something specific?

Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.