**Total Chapters**:

4+5 = 9

**Number of Pages**:

329+4 (Book 1) and 352+4 (Book 2)

**Release Date**:

19 July 2020

**Translation**:

Spanish (2021), Bulgarian CP3.18 (2021)

**Selling price (Printed)**

Book 1: 19.99 USD (+Shipping Cost), Buy A5 Paperback

Book 2: 22.99 USD (+Shipping Cost), Buy A5 Paperback

**Selling price (eBook)**

Book 1: 17.99 USD (instant delivery), Buy eBook/PDF

Book 2: 20.99 USD (instant delivery): Buy eBook/PDF

Both released on 19 August 2022

**Book Sales Status at lulu.com**

Average daily sales: 8071/1277/2 (Jul20-Dec23) ~= 3.16 book(s)/day.

- Even gentler intro: C++ 17, Python 3 (NEW), Java 11, and OCaml (NEW - not used in any programming contest yet but available at Kattis; the inclusion of OCaml is due to generous sponsorship towards CP4 writing project from Tezos Southeast Asia
- NEW: Add writeup about the two main contests supported by this book: IOI and ICPC — including tips to do well from our decades of experience
- NEW: Introduction of Kattis online judge, on top of (UVa) online judge
- NEW: Addition of 1783 (more than double) UVa and especially Kattis programming exercises compared to CP3, i.e., 1675 problems in CP3 compared with 3458 problems in CP4
- NEW: To help our readers, we have selected 1 entry level (the most basic UVa or Kattis problem for that category), plus additional top 3 UVa and top 3 Kattis starred programming exercise problems (total = 7) per category, with the 'less interesting (but still good)' exercises only displayed at Methods to Solve page
- We move basic string and simpler Ad Hoc string processing problems from Book 2 (Chapter 6) to Chapter 1 so that readers can be presented with (harder to parse/format) String I/O-related problems earlier
- We share the most up-to-date competitive programming techniques at the time of release (year 2020, but admittedly will get less up-to-date over time)

- Much closer integration with VisuAlgo; addition of Python and OCaml data structures-related libraries
- REORGANIZATION: We move Inversion Index, Sorting in Linear Time, Bracket Matching, Postfix Conversion/Calculator, all from Book 2 (Chapter 9) to this chapter
- REORGANIZATION: We move Big Integer from Book 2 (Chapter 5) to this chapter as linear data structure with library (for Python and Java)
- Expanded discussion about Binary Heap, Hash Table (DAT and other proper hashing libraries), and balanced Binary Search Tree (bBST, and its versatility as powerful PQ/Tree Sort)
- REORGANIZATION: We move Order Statistics Tree from Book 2 (Chapter 9) to this chapter as extension of bBST (and other techniques—see Fenwick Tree below)
- NEW: using unordered_map/unordered_set more prominently
- NEW: we expand discussion about graphs that have non-integer labels and various special graph data structures
- REORGANIZATION + NEW: we present Fenwick Tree first before Segment Tree. For Fenwick Tree, we add order statistics, Range Update Point Query, Range Update Range Query, For Segment Tree, we add Range Update (Lazy Propagation)

- NEW: Pre-calculate answers and Try all possible answers categories added in Complete Search section; REORGANIZATION: We move Maths-related Iterative Brute Force from Book 2 (Chapter 5) to this chapter
- REORGANIZATION: We move ternary search from Book 2 (Chapter 9) to after discussion of Binary Search the Answer (BSTA) in D&C section
- REORGANIZATION: Greedy (bipartite) matching listed as classic greedy algorithm; NEW: We add new category: Greedy problems that involves the usage of Priority Queue for dynamic ordering
- Enhanced presentation of 'DP' LIS using the faster O(n log k) solution and DP-TSP implementation up to n=18

- Much closer integration with VisuAlgo; addition of Python and OCaml implementation of these graph algorithms
- REORGANIZATION: We set Kosaraju's as new default SCC finding algorithm
- NEW: We significantly expand the Shortest Paths section to cover its many known 'classic' variants. We discuss two Dijkstra's implementations in more details
- NEW: Basic Graph (Bipartite) Matching problem is now integrated in this chapter with details later in Chapter 8; We change Fleury's algorithm to Hierholzer's algorithm for finding Eulerian path

- REORGANIZATION: Ad Hoc mathematics section reorganized and expanded, e.g., discussion of Fractions-related problems
- NEW: Number theory section significantly expanded, especially the Modular Arithmetic, Modular Multiplicative Inverse, Fermat's little theorem, Extended Euclid, Linear Diophantine Equation
- NEW: Combinatorics expanded with modular arithmetic component
- Floyd's cycle-finding algorithm explanation is now with VisuAlgo screenshots
- REORGANIZATION: Matrix Power is now integrated in this chapter (from Chapter 9) and discussed in context of modular arithmetic too

- Python is now used for various basic string processing stuffs
- NEW: Discussion of Digit DP technique
- Further strengthening of Trie/Suffix Trie/Tree/Array explanation
- NEW: We add String Hashing as alternative way to solve some string-related problems
- REORGANIZATION: We integrate discussion of two common string-related problems: anagram/palindrome with their associated techniques

- Further enhancement of existing library routines. Main change: The usage of Andrew's Monotone Chain convex hull algorithm on top of the improved but still longer/slower Graham's scan algorithm
- Major rewrite of the explanations of various algorithms on polygon

- REORGANIZATION: We move Network Flow from Book 1 (Chapter 4) to here as it is still outside the IOI syllabus and the full form of Graph Matching (from Chapter 4/9) to here before some form of matching is used in the discussion of NP-complete/hard problems
- Expanded discussion of Network Flow topic. NEW: Dinic's algorithm (with its implementation) is now the preferred max flow algorithm instead of Edmonds Karp's algorithm
- Graph Matching: All augmenting path based matching algorithm has randomized greedy pre-processing step upfront by default; addition of more detailed overview of weighted MCBM, unweighted MCM, and weighted MCM
- REORGANIZATION + NEW: We discuss NP-complete decision and/or NP-hard optimization problems in competitive programming and reorganizes problems that were previously just labeled as brute force or DP problems to this category
- NEW: Many new exercises/insights about combining problem types in the Problem Decomposition section

- Even more collection of rare algorithms, data structures, and/or programming problems that have not been listed in the first eight chapters
- NEW topics that are not in CP3: Square Root Decomposition, Heavy-Light Decomposition, Tree Isomorphism, De Bruijn Sequence, Fast Fourier Transform, Chinese Remainder Theorem, Lucas' Theorem, Combinatorial Game Theory, Egg Dropping Puzzle, Dynamic Programming Optimization, Push-Relabel algorithm, Kuhn-Munkres algorithm, Edmonds' Matching algorithm, Constructive Problem, Interactive Problems, Linear Programming, and Gradient Descent

- More collection of data structure/algorithm/competitive programming keywords for easier search
- Listing of 3458 UVa + Kattis problems that we have solved