Open-source project
alxli/algorithm-anthology avatar
alxli/algorithm-anthology

A3C5: A Contest Codebook That Prioritizes Clarity Over Compactness

Alex's Anthology of Algorithms: Common Code for Contests in Concise C++ (A³C⁵) - Work in Progress!

175 stars46 forksTeXGPL-2.0

At a glance

What is it?
Alex's Anthology of Algorithms is a TeX-sourced collection of concise C++ implementations for competitive programming. It targets ICPC-style contests and emphasizes readable, adaptable code over the shortest possible snippets.
Who is it for?
Adopt this anthology if you compete in ICPC-style contests that allow printed material, or if you want a reference for clean C++17 implementations of common algorithms. Skip it if you are a beginner looking for a textbook, or if you need production-grade code with external dependencies.
Can I use it commercially?
Yes, with conditions. GPL-2.0 is a copyleft licence: if you distribute software that includes it, you must release that software's source code under the same licence. Running it internally without distributing it does not trigger that obligation.
Is it still maintained?
Yes. The repository last received commits 31 days ago.
What is it written in?
Mainly TeX, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 6, 2026, and from our analysis. They are not legal advice.

Editorial analysis

What This Codebook Solves and Who It Serves

The anthology addresses a specific pain point: knowing an algorithm conceptually but lacking a clean, correct implementation when time pressure hits. It is written for competitive programmers who participate in events like ICPC, where printed reference material is allowed. The README is explicit that this is not a first textbook. It assumes you already understand the underlying ideas. Instead, it focuses on implementation details, interfaces, edge cases, and the choices that make familiar algorithms usable in real code. If you are a contest participant who wants to avoid re-deriving a segment tree or a suffix array during a five-hour contest, this collection is aimed at you. The author states it began as a personal contest codebook, which explains the single-file snippets and predictable APIs.

The Structure: Documentation, Implementation, Example

Each section in the anthology follows a consistent layout. Source files are organized as documentation, then reusable implementation, then example usage. The reusable part ends at a marker labeled 'Example Usage'. Everything after that marker exists only to make the file compile and demonstrate itself. The README advises that when adapting a section, you drop the example block and keep the implementation above it. This structure is practical for a codebook: you can read the documentation to understand the interface, copy the implementation, and ignore the example harness. The consistency in naming and example styles across chapters is a deliberate design choice, so moving from one algorithm to another should feel familiar. This is a clear improvement over scattered snippets found in online forums, where conventions vary wildly.

Guiding Principles: Clarity Over Brevity

The README lists six guiding principles: clarity, concision, efficiency, adaptability, consistency, and portability. The most notable is the tension between concision and clarity. The author admits that the code is often more verbose than compact ICPC snippets. The extra lines buy clearer names, configurable types, safer defaults, reset functions, and explicit handling of variants. This is a deliberate trade-off. In a contest, you might want the shortest possible code to type quickly, but the author argues that short code helps only when it removes noise, not when it hides the idea. For a printed codebook, clarity matters more because you are not typing from scratch; you are copying from a reference. The documentation also notes that educational-only sections are labeled as such, so you can skip them if you are only looking for usable implementations.

Getting It Running: Compilation and Portability

The anthology targets modern GCC or Clang environments with C++17. The README gives a typical compile command: g++ -std=c++17 -O2 -Wall -pedantic. That is the exact command you would use to compile any example from the book. The portability note is detailed: most code assumes common contest-platform type sizes, such as 8-bit char, 32-bit int and float, and 64-bit double and long long. Sections that rely on long double width or precision say so explicitly. The code targets ISO C++17, with a few documented exceptions. These include GCC/Clang integer extensions like __int128 and __uint128_t, which are usually guarded with a portable fallback when overflow safety matters. Compiler builtins like __builtin_popcount() and __builtin_clz() are used, and the README notes that C++20's <bit> header standardizes many of them. GNU policy-based data structures like __gnu_pbds::tree appear in a few sections. There is also a documented representation assumption for signbit_() in the math utilities, which assumes an IEEE-like floating-point sign bit layout.

The PDF and Website: How to Access the Content

The repository provides two ways to browse the content. You can visit the website at algorithms.alexli.ca to browse all sections, or download the PDF version v1.0 directly from the GitHub repository. The README issues a warning: 'Beware of older versions in circulation which are riddled with bugs.' That warning is significant. It implies that the project has been through multiple versions, and that some versions have known correctness issues. The current PDF is v1.0, but the project is described as a work in progress. This means the repository content may be more current than the PDF, or vice versa. If you are preparing for a contest, you should verify which version you are using and cross-check any critical code against the website or the latest source files. The warning also suggests that the author has found bugs in older releases, so relying on an outdated copy could cost you a submission.

Limitations and When It Is the Wrong Tool

The anthology has clear boundaries. It is not a learning resource for beginners. If you do not already understand the algorithms, the sparse theory will not be enough. The README says each section gives only enough theory to orient the implementation: problem, interface, assumptions, and complexity. That is not a substitute for a textbook. Another limitation is the reliance on non-standard compiler extensions. While the README notes these are common in contest environments, they are not portable to all platforms. If you are working on a system that does not support __int128 or __gnu_pbds, you will need to adapt the code. The project also assumes a specific set of type sizes, which may not hold on all platforms. The README explicitly states that long double width and precision are implementation-dependent, and sections relying on it say so. For production software, this codebook is the wrong tool because it is designed for contest constraints, not for maintainability or external dependencies. The author even encourages you to annotate, delete, and rename functions to fit your habits, which implies the code is a starting point, not a final product.

Alternatives: What Else Is Out There

The most direct alternative is the classic competitive programming codebook compiled by Stanford University's ACM team, often distributed as a PDF. That codebook takes a different approach: it prioritizes extreme brevity and density, packing as many algorithms as possible into a limited number of pages. The A3C5 anthology explicitly contrasts itself with that style, stating that its code is often more verbose than compact ICPC snippets. The Stanford codebook is designed for quick lookup during a contest, with minimal comments and terse variable names. A3C5, by contrast, favors explanatory comments and configurable interfaces. Another alternative is the book 'Competitive Programming' by Steven and Felix Halim, which is a full textbook with explanations and code. That is better for learning, but it is not a quick reference. The choice depends on your needs: if you want maximum density in a printed book, the Stanford codebook wins. If you want code that is easier to adapt and understand under pressure, A3C5 may serve better.

Maintenance and License Implications

The project is licensed under GPL-2.0. That has implications if you plan to use the code in your own projects. GPL-2.0 is a copyleft license, so if you distribute a program that includes code from this anthology, you may need to release that program under the same license. This is not legal advice, but it is a consideration for anyone building a commercial product. For contest use, where you are not distributing software, the license is likely irrelevant. The repository has no recent releases listed, and the last push is unknown, which suggests the project may not be actively updated. The README describes it as a work in progress, so there is no guarantee of ongoing maintenance. The PDF is at v1.0, but the source may have evolved. If you adopt this anthology, you should check the repository for updates before each contest season. The author's warning about older versions implies that bugs have been fixed over time, so using the latest source is important.

Editorial conclusion

Adopt this anthology if you compete in ICPC-style contests that allow printed material, or if you want a reference for clean C++17 implementations of common algorithms. Skip it if you are a beginner looking for a textbook, or if you need production-grade code with external dependencies. Before relying on any section, verify the version: the README warns that older versions in circulation are buggy, and the project is a work in progress. Check the PDF version (v1.0) or the website, and stress-test any code you plan to use in a contest. The repository's value lies in its explicit documentation of edge cases and trade-offs, so read those notes before copying.

Frequently asked questions

How do I adapt a section from algorithm-anthology into my own code?

Each file is documentation, then reusable implementation, then example usage, and the reusable part ends at the `Example Usage` marker. The instruction is to drop the example block and keep the implementation above it, since everything after the marker exists only so the file compiles and demonstrates itself.

Why is algorithm-anthology code longer than typical contest snippets?

Concision is defined as removing noise rather than hiding the idea, so the code is often more verbose than compact ICPC snippets on purpose. The extra lines buy clearer names, configurable types, safer defaults, reset functions and explicit handling of variants.

Does algorithm-anthology need compiler extensions beyond standard C++17?

Most code targets ISO C++17, with four documented exceptions: `__int128` and `__uint128_t`, compiler builtins like `__builtin_popcount()`, GNU policy-based data structures such as `__gnu_pbds::tree`, and representation assumptions like `signbit_()` expecting an IEEE-like sign bit layout. Each is noted at its point of use.

What license is algorithm-anthology under?

GPL-2.0, with the LICENSE file at the top of the repository. The project is also described as work in progress, and the README warns that older versions in circulation are riddled with bugs.

Can algorithm-anthology be used to learn algorithms from scratch?

Not as a first textbook, by its own account. The stated method is to study the idea, prove the invariant or recurrence, implement it yourself, then compare against the code, since the differences reveal the practical choices. Each section carries only enough theory to orient the implementation.

Official sources

  1. Official README
  2. Project repository
  3. README
  4. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/alxli-algorithm-anthology.svg)](https://hysenlabs.com/projects/alxli-algorithm-anthology)