Python programs operate on objects with explicit input, ownership and failure contracts.
Learning roadmap
This section contains 46 written lessons or quiz banks. Programs are verified on CPython 3.14.6. Standard-library lessons target 3.11+ syntax; lessons using data, web, machine-learning or testing packages state their tested dependencies separately. Framework programs use local test clients, not a deployed service. Read the stated limits before adapting a fixture into an application.
Search and traversal
Read the contract, run its program and inspect the failure case.
- Python binary search: use a half-open interval and require sorted input
- Python graph BFS: mark a vertex when it enters the queue
Selection, nesting and cached state
Read the contract, run its program and inspect the failure case.
- Python heapq top-k: define ties before ranking frequencies
- Python bracket stack: reject mismatches at the first invalid close
- Python memoization: cache bounded states without hiding recursion depth
Ordering and connectivity
Read the contract, run its program and inspect the failure case.
- Python merge sort: stable ordering without editing the input
- Python topological sort: dependency order and cycle rejection
- Python Dijkstra: nonnegative weights and stale heap entries
- Python union-find: connected groups with path compression
Text indexes and DP
Read the contract, run its program and inspect the failure case.
- Python trie: exact words, prefixes and node allocation
- Python prefix-function search: overlapping matches without rescanning
- Python longest common subsequence: rolling-row DP and its limits
- Python 0/1 knapsack: descending capacity prevents item reuse
Linked and hierarchical state
Read the contract, run its program and inspect the failure case.
- Python linked-list reversal: validate cycles before changing links
- Python iterative tree traversal: shared nodes are not a tree
Range, tree and signed-graph invariants
Read the contract, run its program and inspect the failure case.
- Python edit distance: rolling rows for insert, delete and replace
- Python sliding window: longest span without repeated symbols
- Python Bellman-Ford: negative edges and reachable negative cycles
- Python Kruskal: minimum spanning forests and disconnected graphs
- Python segment tree: point replacement and half-open range sums
- Python BST deletion: replace a two-child node with its successor
Balanced indexes, pruning and reconstruction
Read the contract, run its program and inspect the failure case.
- Python AVL insertion: rotate while preserving ordered keys and heights
- Python trie deletion: remove one word without losing its prefix neighbors
- Python lazy segment tree: defer interval additions and retain correct totals
- Python edit scripts: reconstruct and verify an alignment instead of only counting it
Deletion repair, edge identity and compressed text indexes
Read the contract, run its program and inspect the failure case.
- Python AVL deletion: rebalance after removing a key and replacing its successor
- Python strongly connected components: partition a directed dependency graph
- Python graph bridges: track edge identity when parallel links are allowed
- Python compressed trie: merge single-child paths without losing terminal words
- Python longest palindrome: expand around odd and even centers
Graph removals, edge trails and sequence reconstruction
Read the contract, run its program and inspect the failure case.
- Python articulation points: find vertices that separate an undirected graph
- Python graph condensation: collapse directed cycles into an acyclic component graph
- Python directed Euler trail: consume every edge identity exactly once
- Python Z string matching: reuse a known matching interval without losing overlaps
- Python longest increasing subsequence: reconstruct a strict sequence from tail candidates
Mutable compressed edges and optimal selection
Read the contract, run its program and inspect the failure case.
- Python compressed trie updates: split on insertion and compact after deletion
- Python bipartite matching: augment an assignment instead of taking the first free slot
- Python weighted interval scheduling: reconstruct the accepted nonoverlapping jobs
All-pairs paths and residual capacity
Read the contract, run its program and inspect the failure case.
- Python Floyd-Warshall: all-pairs costs with negative-cycle rejection
- Python maximum flow: residual edges permit earlier choices to be revised
Heuristic paths and prefix totals
Read the contract, run its program and inspect the failure case.
- Python A-star grid search: use an admissible lower bound for shortest paths
- Python Fenwick tree: update one amount and query prefix totals
Bounded windows, weighted routes and capacity
Read the contract, run its program and inspect the failure case.
- Python sliding-window maximum: retain only useful deque indexes
- Python 0-1 BFS: shortest paths when every edge costs zero or one
- Python running median: two heaps with an exact even-count result
- Python binary search on capacity: prove the feasibility predicate
Continue learning
Move between tutorial, collections, advanced material and practice using the subject tabs. The sidebar changes with each section; related examples keep one canonical lesson URL.
