Want to kill it at your job interview in the tech industry? Want to win that coding competition? Learn all the algorithmic techniques and programming skills you need from two experienced coaches, problem setters, and jurors for coding competitions. The authors highlight the versatility of each algorithm by considering a variety of problems and show how to implement algorithms in simple and efficient code. Readers can expect to master 128 algorithms in Python and discover the right way to tackle a problem and quickly implement a solution of low complexity. Classic problems like Dijkstra's shortest path algorithm and Knuth-Morris-Pratt's string matching algorithm are featured alongside lesser known data structures like Fenwick trees and Knuth's dancing links. The book provides a framework to tackle algorithmic problem solving, including: Definition, Complexity, Applications, Algorithm, Key Information, Implementation, Variants, In Practice, and Problems. Python code included in the book and on the companion website.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
# Competitive Programming in Python: 128 Algorithms to Develop Your Coding Skills
## 【One-Line Pitch】
A practical, problem-driven handbook that teaches 128 classic algorithms and data structures in clean Python, aimed at competitive programmers and tech-interview candidates who want to move from knowing theory to implementing efficient solutions quickly.
## 【Book Arc】
- **Opening (~0%–10%)**: Introduces the competitive programming landscape, Python's suitability for contests, and the essential mechanics of input/output, complexity analysis (Landau notation), and core data structures like queues, heaps, and union-find.
- **Early (~10%–32%)**: Covers fundamental techniques—list/dictionary comprehensions, bit manipulation, binary search, and the "Frosting on the Cake" worked example that demonstrates how to reduce a problem's complexity by observing symmetries.
- **Middle (~32%–48%)**: Dives into string algorithms (Knuth–Morris–Pratt, Rabin–Karp, Manacher) and sequence problems (Levenshtein distance, longest common subsequence, longest increasing subsequence), introducing dynamic programming as a unifying method.
- **Late (~48%–75%)**: Extends to arrays (merge of sorted lists, range queries, maximum subarray sum) and graph algorithms, including Dijkstra's shortest path and other classic problems.
- **Ending (~75%–100%)**: Covers advanced data structures like Fenwick trees and dancing links, plus specialized techniques for contest problems; the book closes with a framework for approaching any algorithmic problem systematically.
## 【Key Takeaways】
- **Python is a legitimate contest language** (Early): Despite C++/Java dominance, Python's clarity lets you express algorithms without boilerplate; judges often adjust time limits, though acceptance isn't guaranteed—so optimize carefully.
- **Complexity analysis is the first step** (Early): Before writing any code, determine the required time complexity from input size limits; this rules out naive solutions and guides your choice of algorithm.
- **Master the core data structures** (Early): Heaps (for priority queues), union-find (for partitions), and queues implemented with two stacks are building blocks for dozens of algorithms; understanding their internals makes you faster at applying them.
- **Dynamic programming is a mindset** (Middle): Break problems into subproblems, compute solutions in sweep order, and memoize—this technique powers shortest paths in grids, edit distance, and subsequence problems.
- **String algorithms reward cleverness** (Middle): Knuth–Morris–Pratt uses maximal boundaries to achieve linear-time pattern matching; Rabin–Karp trades some correctness risk for simplicity via hashing; both beat naive O(nm) approaches.
- **Bit manipulation is a hidden superpower** (Early): Encoding sets as integers and using bitwise operations (e.g., extracting the minimum element) enables exponential-time algorithms for small inputs, like the three-partition problem.
- **Observation beats brute force** (Early): The "Frosting on the Cake" example shows how permuting rows/columns preserves the answer, reducing an O(n²) problem to O(n)—always look for symmetries before coding.
## 【Reading Tips】
- **Skim the Preface and Chapter 1** if you're already comfortable with Python basics; focus instead on the complexity section and the "Frosting on the Cake" example, which teaches the problem-solving mindset.
- **Deep-read the string and sequence chapters** (Chapters 2–3): These are the heart of the book and introduce the most reusable techniques (boundaries, hashing, dynamic programming). Work through the KMP example by hand.
- **Treat code as reference, not gospel**: The authors deliberately avoid numpy for portability; adapt their implementations to your style, but keep the algorithmic core intact.
- **Use the companion website (tryalgo.org)** to test implementations against online judges—this is where the real learning happens.
- **Skip the advanced data structures** (Fenwick trees, dancing links) on first read; return when you encounter problems that specifically need them.
## 【Coverage Limits】
This guide synthesizes the first ~48% of the book (intro, strings, sequences, arrays); later chapters on graphs, advanced data structures, and specialized techniques are not covered in detail here.
##
Excerpt 1
s 72 4.1 Merge of Sorted Lists 73 4.2 Sum Over a Range 74 4.3 Duplicates in a Range 74 4.4 Maximum Subarray Sum 75 Preface Algorithms play an important role...
ndard output. For example, if the input file is called test.in, and your program is prog.py, the contents of the input file can be directed to your program w...
f[S | (1 << i)] = f[S] + x[i] for A in range(1 << len(x)): for B in range(1 << len(x)): if A & B == 0 and f[A] == f[B] and 3 * f[A] == f[-1]: return (A, B, (...
ttern t in a string s, simply with the expression s.find(t). A second optional parameter permits the search to be started at a certain index in s. This func-...
add to the solution a new interval [last,x), where x is the current position of the sweep line and last is the last sweep position where nb_open became posit...
his counter is equal to the number of children of the node, then the processing of the node is finished, and the node is added to the sequence order. This se...
we select to colour black? The choice is made with a vertex v with the smallest dist[v]. Why is this the correct choice? Consider an arbitrary s−v path P . S...
: if u not in graph[v]: if type(graph[v]) is list: graph[v].append(u) if capac: capac[v][u] = 0 else: assert type(graph[v]) is dict graph[v][u] = 0 142 Match...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
Competitive Programming in Python 128 Algorithms to Develop your Coding Skills (Christoph Dürr, Jill-Jênn Vie)(Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
Competitive Programming in Python 128 Algorithms to Develop your Coding Skills (Christoph Dürr, Jill-Jênn Vie)(Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment