Competition Programming and Problem Solving

15-195 and 15-295 Spring 2026

In this course you will learn the techniques and skills needed to solve algorithmic programming contests problems such as those that appear on the International Collegiagte Programming Contest (ICPC), Codeforces, DMOJ, and AtCoder. Much of your time will be spent writing programs on your own to solve problems. (If you are interested in participating in the ICPC see this page.)

But the skills you will pick up from the course are far more valuable than just enabling you to win contests. Many of the algorithms and techniques are classic ones that every computer scientist should know. You will also learn to think about algorithms in a deeper way, because many of the problems require you have to devise a new algorithm, not just apply a classic one. You will also become highly fluent in a programming language of your choice. These skills will be of great value in your other classes, in your job interviews, and in your future work, not to mention the satisfaction you will get from solving these problems.

Basic Information
Weekly Problems
Rules and Academic Integrity
Grading
Logistics
Training Resources
Learning Material
Diversity, Equity and Inclusion

Basic Information

The regular weekly contests will take place Wednesdays beginning at 7:05pm in Scaife Hall 236, and last 2 hours (you don't have to stay the whole time.) Most contests will have a theme, and will be preceeded by a lecture on the theme of the contest. The lecture will begin at 6:30 in the same room. The theme will be listed with the contest, along with links to tutorials or background materials. During the contests, the instructor and/or TA will be available for help in the classroom, or via Discord.

For more information on how to join these groups, etc, see the Logistics section below.

Weekly Contests

Week #11 No theme

Contest Link: Here
Solutions: For Editing  For Viewing

Week #10 Tricks on Graphs and Trees

Tonight's contest will cover such techniques as binary lifting, the heavy-light decomposition, and the centroid decomposition of trees. These allow you to "tame" unruly trees that are super unbalanced coerce them into "behaving" like balanced trees. For example, they give efficient algorithms for finding least common ancestors (LCA)s in a tree.

Contest Link: Here
Solutions: For Editing  For Viewing

Week #9 Strings

This weeks contest features string algorithms. You will find problems for which Karp-Rabin, KMP, and Suffix Arrays are useful. Other problems are ad-hoc and will feature more general ideas like DP, or binary search.

In the lecture I'll talk about Karp-Rabin fingerprinting, suffix trees and suffix arrays.

The KMP Algorithm Link
Karp-Rabin Fingerprinting:  Basic Tutorial   The Oracle Method
The Suffix Array and Longest Common Prefix (LCP) Array Link  
The Z Algorithm Link

Contest Link: Here
Solutions: For Editing  For Viewing

Week #8: Additional Tricks

  1. Two Finger Search
  2. Max in Sliding Window
  3. Merging Two Objects by Changing the Small One

(I lectured on these in class, but some day I'll get around to writing these up.)

Contest Link: Here
Solutions: For Editing For Viewing

Week #7: Strongly Connected Components

This week we explore the applications of strongly connected components in a directed graph. For a pair of vertices u and v, if u is reachable from v, and also v is reachable from u, then they are in the same strongly connected component. This is an equivalence relation among vertces, so it partitions the vertices into its strongly connected components.

There are two beautiful algorithms for computing the SCCs of a graph. They are Tarjan's algorithm and Kosaraju's algorithm. They are both simple, stack based, and run in linear time. I've included two slides in the links below which give the full pseudocode for each of the algorithms.

You should do your own implementation of one of these algorithms to use on today's contest. (Do not search for code. Spend the time to write your own based on the pseudocode I've supplied. It's pretty simple.)

Tarjan's SCC Algorthm Here
Kosaraju's SCC Algorithm Here
Contest Link Here
Solutions: For Editing For Viewing

Week #6: Tree Data Structures

Today's contest features data tree data structures. They typically have O(log n) performance when the data stored is of size n. There are many kinds of trees which you can read about in the links below. They include Fenwick Trees, Segment Trees, and augmented binary search trees. We'll also discuss lazyness, which would allow you to support bulk-assignments (assign all elements in a range with indices in a range [i,j] to some constant c) while supporting lookups, and preserving the O(log n) time per operation.

For this contest, feel free to reference and use code from the articles below on segment trees (simpler to reason about, more versatile) or Fenwick trees (easier to implement, better constant factor).

Seg Tree and Fenwick Tree notes from 451 (includes code) Here
Union-Find notes from 451 Here
CP-Algorithms notes on Seg Trees Here
CP-Algorithms notes on Fenwick Trees Here
Contest Link: Here
Solutions: For Editing For Viewing

Week #5: Dynamic programming

This week, we will practice the use of dynamic programming (DP) as a technique to solve programming competition problems. DP is quite possibly the most frequently occuring algorithmic technique used in competitions, with every ICPC contest always featuring at least one, if not several problems that require it. Mastering this technique is key to becoming a strong competitive programmer. DP revolves around two key concepts, optimal substructure, which means that a problem can be solved by breaking it into smaller versions of itself (much in the same way as divide and conquer), and memoization of overlapping subproblems, which means to cache the solutions to the smaller problems in case they need to be solved multiple times. Of all topics in competitive programming, it probably requires the most practice in order to master, so get started!

Here are some cp-algorithms pages about DP: intro to DP, knapsack, LIS. Here are some other examples: Atcoder DP Tasks.

Contest Link
Solutions: For Editing For Viewing

Week #4 (February 4): Graph Search 2: Shortest Paths and Friends

The problems this will will feature shortest path algorithms, such as Dijkstra's algorithm, the Bellman-Ford algorithm, or the Floyd-Warshall algorithm. There will also be the need to compute minimum spanning trees using algorithms such as Kruskal's and Prim's.

Lecture: Video
Lecture Slides: Dijkstra's Algorithm
451 Lecture notes: Bellman-Ford and Floyd Warshall
Contest Link: Here
Solutions: For Editing For Viewing

Week #3 (January 28): Graph Search 1: BFS and DFS

This week we will talk about graph algorithms. This is a topic that will probably span multiple weeks as we cover things like shortest paths, minimum spanning trees, and network flows. For this week, we will focus on the fundamentals, and cover things like how to represent graphs and how to implement graph traversal algorithms (breadth first search and depth first search), and shortest path algorithms.

Today's lecture explores the following links:

DFS:   CP-Algorithms Page   Additional Notes   A Practice Problem
BFS:   CP-Algorithms Page   Additional Notes   A Practice Problem

Lecture: Video   DFS code in C++   BFS code in C++
DFS and Biconnected Components: 451 Lecture Notes

Contest Link: Here
Solutions: For Editing For Viewing

Week #2 (January 21): Binary Search

This week, we will solve problems that use the binary search technique. You might think of binary search as an algorithm for finding an element in a sorted list, but it is actually a much more general technique than that, and can be used to solve a wide range of problems.

Suppose you have a monotonic function f() over a range [0,n] where f(0) is 0 and f(n) is 1. Here monotonic means it does not decrease as you move from 0 to n. You want to find the index i where f(i)=0 and f(i+1) = 1. Binary search can do this in log n evaluations of f().

CP Algorithms Binary Search Site:  cp-algorithms.com/nummethods/binarysearch.html
C++ Code for binary search and ternary search
Contest Link: Here
Solutions: For editing For Viewing

Week #1 (January 14): Introduction

This week has no particular algorithmic theme. Instead, we will go over the basics of competitive programming and do our first contest on vjudge.net. Please make sure you have a Vjudge account ready to go and understand how to upload your solutions to the problems.

If you don't know how to read from standard input and write to standard output, here's a tutorial showing how to do it.

Contest Link: Here
Solutions: For editing For viewing

Rules and Academic Integrity

You can make use of generic on-line resources while solving problems. These include things like language documentation, API documentation, algorithm descriptions, terminology, etc. You are allowed to use any code you have written, at any time in the past, for any purpose. However, you should not search for or make use of code written by others to solve the specific assigned problem. It is also forbidden to use AI to solve these problems. The purpose is to learn to solve these problems yourself.

So to summarize, each student should write his or her own code. If you're stuck on a problem, you are welcome to discuss it with another student in the class, or the course staff. But you cannot copy another student's code, or ask an AI for assistance.

The violations described above are regarded as an academic integrity violation, and -- depending on the severity -- will result in penalties and/or be reported to the appropriate university authorities.

Grading

This course is 5 units. Each week you will be given several problems to try to solve during class. You will be allowed (for half credit) to solve these problems during the week after the contest ends. You can also get credit for solving problems during rated contests on Codeforces. (This site run rated contests approximately every two weeks.)

To be more specific, you can earn points from the following sources:

The differences between 15-195 and 15-295 are: Students enrolled in 15-295 will not get credit for problems A and B of the weekly contests, but 15-195 students can. A student can take 15-195 only once, but 15-295 can be taken repeatedly.

Here is how your grade is determined:

score ≥ 25: A
score ≥ 15: B
score ≥ 10: C
score ≥   5: D

Logistics

Training Resources

This semester Richard Peng is teaching 15495, Topics in Algorithmic Problem Solving. It's Tuesday and Thursday 2 to 3:20PM in Porter Hall 126A. Many techniques that are useful for contest solving will be covered.

There are many online resources available for you to train with if you intend to become a serious competitive programmer. You can find thousands of practice problems for you practice and improve your skills. Some good places to find practice problems include:

Learning Material

If you are a beginner looking for resources to learn the various topics that appear in typical contests, some good sources are:

Diversity, Equity, and Inclusion

We must treat every individual with respect. We are diverse in many ways, and this diversity is fundamental to building and maintaining an equitable and inclusive campus community. Diversity can refer to multiple ways that we identify ourselves, including but not limited to race, color, national origin, language, sex, disability, age, sexual orientation, gender identity, religion, creed, ancestry, belief, veteran status, or genetic information. Each of these diverse identities, along with many others not mentioned here, shape the perspectives our students, faculty, and staff bring to our campus. We, at CMU, will work to promote diversity, equity and inclusion not only because diversity fuels excellence and innovation, but because we want to pursue justice. We acknowledge our imperfections while we also fully commit to the work, inside and outside of our classrooms, of building and sustaining a campus community that increasingly embraces these core values.

Each of us is responsible for creating a safer, more inclusive environment.

Unfortunately, incidents of bias or discrimination do occur, whether intentional or unintentional. They contribute to creating an unwelcoming environment for individuals and groups at the university. Therefore, the university encourages anyone who experiences or observes unfair or hostile treatment on the basis of identity to speak out for justice and support, within the moment of the incident or after the incident has passed. Anyone can share these experiences using the following resources:

All reports will be documented and deliberated to determine if there should be any following actions. Regardless of incident type, the university will use all shared experiences to transform our campus climate to be more equitable and just.


Danny Sleator
Last modified: Wed Apr 1 23:38:12 2026