Skip to content

Chapter 0: Fundamentals

This is where everything begins. Before you can think about algorithms, you need fluency in C++, comfort with complexity analysis, and muscle memory for the STL. This chapter gives you the vocabulary and tools that show up in every single contest solution — from reading input fast enough to avoid TLE, to encoding subsets as bitmasks for brute-force searches. If you skip this chapter, you'll constantly trip over language mechanics instead of focusing on the actual problem.

Going to: Chapter 1 — Essential Techniques — core problem-solving techniques like binary search, greedy, and prefix sums
Bridge: BRIDGE-to-techniques.md — why fundamentals matter before learning techniques

Topics at a Glance

#TopicDifficultyKey Trigger Phrase
01C++ Language EssentialsBeginner"How do I write idiomatic C++ for contests?"
02Fast I/O and PragmasBeginnerTLE on correct solution → slow I/O
03Complexity AnalysisBeginner"Will O(n²) pass for n = 10⁵?"
04Arrays and StringsBeginnerAny problem with sequences or text
05STL ContainersBeginner"Which container gives me O(log n) lookups?"
06STL AlgorithmsBeginner"Is there a built-in for this?"
07Bit ManipulationIntermediaten ≤ 20 + "subsets" or "choose elements"
08Bitset OptimizationIntermediate"Need O(n/64) speedup on boolean vectors"
09Math ToolkitBeginnerGCD, power, factorials in contest code
10Modular Arithmetic BasicsBeginner"Print answer mod 10⁹+7"
11Recursion and BacktrackingBeginner"Generate all" + small n (≤ 20)
12Graph and Tree IntroBeginnerFirst encounter with nodes and edges
13Debugging and Stress TestingBeginnerWA on test 3 and you can't see why
14Bitset TricksIntermediate"O(n²) TLE, bitset gives 64x speedup"

If You Only Read 3 Files

  1. Complexity Analysis — because reading constraints and knowing whether O(n²) will pass is the first thing you do on every problem. Get this wrong and nothing else matters.
  2. STL Containers — because choosing between vector, map, set, and unordered_map is a decision you'll make dozens of times per contest. Know the tradeoffs cold.
  3. Recursion and Backtracking — because recursive thinking is the foundation for DFS, DP, and divide-and-conquer. If you can't think recursively, Chapters 3 and 4 will be a wall.

Cross-Chapter Connections

File Listing

FileTopicLevel
cpp-language-essentialsC++ Language Essentials
complexity-analysisComplexity Analysis
arrays-and-stringsArrays and Strings
stl-containersSTL Containers
stl-algorithmsSTL Algorithms
math-toolkitMath Toolkit
modular-arithmetic-basicsModular Arithmetic Basics
recursion-and-backtrackingRecursion and Backtracking
graph-and-tree-introGraph and Tree Intro
bit-manipulationBit Manipulation⭐⭐
bitset-optimizationBitset Optimization⭐⭐
fast-io-and-pragmasFast I/O and Pragmas
debugging-and-stress-testingDebugging and Stress Testing
bitset-tricksBitset Tricks for CP⭐⭐

Suggested Reading Order

  1. Complexity Analysis — learn to estimate what will pass within time limits
  2. Arrays and Strings — the most common data types in every problem
  3. STL Containers — when to use vector, map, set, queue
  4. STL Algorithms — replace manual loops with standard library calls
  5. Recursion and Backtracking — think recursively and prune branches
  6. Bit Manipulation — encode sets as integers for subset enumeration
  7. Bitset Optimization — squeeze O(n/64) speedups with std::bitset
  8. Fast I/O and Pragmas — avoid TLE from slow I/O
  9. Debugging and Stress Testing — systematic bug-finding techniques
  10. C++ Language Essentials — C++ features every CP coder needs
  11. Math Toolkit — essential math formulas for competitive programming
  12. Modular Arithmetic Basics — handle "mod 10⁹+7" problems correctly
  13. Graph and Tree Intro — visual dictionary of graph and tree vocabulary
  14. Bitset Tricks — competitive programming bitset recipes for 64x speedups

Built for the climb from Codeforces 1100 to 2100.