View On GitHub
ZIP
TAR
DOWNLOADS
competitive-programming
Competitive Programmer's Core Skills by Saint Petersburg State University
Project maintained by
claytonjwong
Hosted on GitHub Pages — Theme by
mattgraham
Week 1: Programming Competitions
Key Concepts
Know various strategies for inventing test cases and testing programs
Understand what programming competitions and algorithmic problems are, what’s the difference compared to other forms of programming
Learn about various platforms dedicated to competitive programming, and what opportunities they offer
Resources
Competitions
Testing
Assignments
Inventing Tests
Addition and Subtraction
Erasing Maximum
Increment
Straight Flush
Week 2: Correctness First
Key Concepts
Deduce simple upper bounds on a solution’s running time and decide if it’s fast enough for a given time limit
Implement brute force solutions with basic recursive backtracking
Understand the connection between code structure and the logic behind it
Resources
Structuring Code
Brute-Force Solutions:
Always Conceptually Correct (but extremely slow)
Intuitive “Proofs” are Wrong
Defining Solution Set
Search Space (ie. set A)
Find an element of a set A which satisfies some property
Find an element of a set A which minimizes/maximizes an objective function
Find the number of elements of a set A satisfying some property
Recursive Backtracking
: Code equivalent to N nested for-loops
Recipe for developing a brute-force solution:
Identify the search space for a problem
Design a method to enumerate all elements of the search space
Time Complexity:
Estimating the number of unit operations in an algorithm
Worst Cases
Big-O Notation
Always calculate the Big-O asymptotic bound before implementation
From Theory to Practice: How to make a solution faster
Focus optimizations on bottlenecks only
First optimize asymptotically (major gain), if and only if this fails, then further optimize constants (minor gain)
Assignments
Quiz
The Cheapest Permutation
The King
Sum of Minimums
Expression Evaluation
Week 3: Common Struggles
Key Concepts
Know how integers are represented
Identify places where integer overflow happens
Know and compare different ways of representing non-integers, including floating point arithmetic
Handle precision issues when performing basic operations with doubles
Distinguish common situations when solution could be simplified by replacing doubles with integers
Apply code structuring to simplify debugging
Auto-check program correctness by identifying invariants and inserting corresponding assertions
Understand motivation and strategy for upsolving
Resources
Insidious Numbers
Getting Unstuck
Binary Knapsack Solution
Assignments
Quiz
Compare Sums
Round Up
Yet Another Sum
Binary Knapsack
Week 4: Technical Problems
Key Concepts
Invent basic greedy solutions and prove their correctness
Understand what programming language features are most important on competitions
Know specialties of popular programming languages
Apply the segment tree data structure to solve problems which require answer queries of certain form
Resources
Greedy Algorithms
Segment Tree
Language Specifics
Maximal Sum Subarray Solution
Assignments
The Most Frequent Symbol
Maximal Distance
Multiset
Maximal Sum Subarray
Week 5: Dynamic Programming
Key Concepts
Subproblems (and recurrence relation on them) are the most important ingredient of a dynamic programming algorithm
Two common ways of arriving at the right subproblem:
Analyze the structure of an optimal solution
Implement a brute-force solution and optimize it
Resources
Dynamic Programming
Make It Sorted Solution
Assignments
Longest Increasing Subsequence
Edit Distance
Sum of Digits
Make It Sorted
Week 6: Dynamic Programming 2
Key Concepts
Recursive vs Iterative
Recursive Advantages
May be faster than iterative if
not
all subproblems need to be solved
Easier to implement since the subproblem order is implicitly found by the recursion
Iterative Advantages
No recursive stack overhead
Memory optimization to only store the previous and current rows
Resources
Dynamic Programming 2
Assignments
Knapsack
Chain Matrix Multiplication
Longest Common Subsequence
Maximal Sum Square