Competition Programming and Problem Solving

15-195 and 15-295 Fall 2023

In this course you will learn the techniques and skills needed to solve algorithmic programming contests problems such as those that appear on the ICPC, Codeforces, DMOJ, and AtCoder. Much of your time will be spent writing programs on your own to solve problems.

Some students may go on to participate in the ECNA regional event, the ICPC North America Championship, and possibly even the ICPC World Finals. The ECNA Regional will take place on Sunday October 29th in Youngstown Ohio.

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 7pm in Posner Hall 151, and last 2.5 hours (you don't have to stay the whole time.) Occasional lectures may take place at 6pm in the same room. They will be announced on Discord. Lectures will cover introductory content aimed at beginners to competitive programming. Although attendance to the lectures is optional, it is strongly encouraged for beginners. During the contests, the instructors 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 #13 -- No Theme

Contest Link: Here
Solutions: For Editing (TODO)   For Viewing (TODO)

Week #12 -- No Theme

Contest Link: Here
Solutions: For Editing   For Viewing

Week #11 -- Applications of Maximum Flow

This week, we will explore even more graph algorithms. In particular, we will be looking at applications of maximum network flow.

Lecture: Video
Lecture Notes: Basic Algorithms  Advanced Algorithms  Min-Cost-Flows
Implementations: Max Flow (C++) Max Flow (Python)
Contest Link: Here
Solutions: For Editing   For Viewing

Week #10 - Geometry

Geometry! Love it or hate it! Geometry problems are often some of the most difficult problems that appear in programming competitions because they can be full of corner cases, precision, and rounding issues. This week, we will practice the fundamental techniques behind solving geometry problems.

Tutorial: Geometry tutorial
Contest Link: Here
Solutions: For Editing   For Viewing

Week #9 -- Segtrees

This week we will cover some advanced data structures that you won't find in your language's standard library. We'll learn about dynamic ranged minimum queries over arrays.

Lecture: Slides
Resources: A poem in honor of SegTrees by Chat GPT 4
Contest Link: Here
Solutions: (no solutions document was created)

Week #8 -- Combinatorial Enumeration (aka Counting Stuff)

This week we will learn how to count things!

Tutorial: Counting tutorial
Contest Link: Here
Solutions: For Editing For Viewing

Week #7 -- No Theme

Contest Link: Here
Solutions: For Editing For Viewing

Week #6 -- Shortest Paths in Graphs

This week, we will continue the theme of graph algorithms and talk about shortest path problems in graphs. The fundamental algorithms that you will need to learn to solve these kinds of problems are breadth-first search (mentioned last time) and Dijkstra's algorithm. Other algorithms, such as Bellman-Ford and Floyd-Warshall are also very useful.

Lecture: Slides
Resources: Lecture notes on Bellman-Ford and Floyd-Warshall
Contest Link: Here
Solutions: For Editing For Viewing

Week #5: Graph Fundamentals

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).

Lecture: Slides   DFS code in C++   BFS code in C++
Resources: Lecture notes on DFS and Strong Components
Contest Link: Here
Solutions: For Editing For Viewing

Week #4: 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!

Lecture Slide: Here
Resources: 451 Notes 1  451 Notes 2
Contest Link: Here
Solutions: For Editing For Viewing

Week #3: 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. Essentially, binary search allows you to solve problems where you must minimize or maximize some quantity subject to some contraint, as long as that constraint is monotone. A constraint is monotone if it is false for all values of x up to some value, and then becomes true after that value. Binary search allows us to efficiently find this partition point, and hence solve the corresponding optimization problem. The practice problems this week should help you to learn to apply this powerfull technique.

Lecture Slide: Here   binary search code   ternary search code
Contest Link: Here
Solutions: For Editing  For Viewing

Week #2: Built-in Algorithms and Data Structures

This week, we will focus on the most commonly used and fundamental algorithms and data structures in competitive programming. We will review and practice using arrays, binary search trees, hashtables, and priority queues. Knowing and understanding how to use these data structures in your favourite programming language is crucial to being able to quickly implement solutions to problems. We will mainly use C++ to demonstrate, but the ideas should be applicable to any language that supports these data structures.

Lecture Slide: Here
Contest Link: Here
Solutions: For Editing For Viewing

Week #1 (August 30): Introduction

This week has no particular algorithmic theme. Instead, we will go over the basics of competitive programming and do our first contest on Codeforces. Please make sure you have a Codeforces account ready to go and understand how to upload your solutions to the problems. You should do some practice problems to get the hang of writing and submitting solutions to the Codeforces system.

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. You're allowed to copy somewhat standard pieces of code (e.g. a primality test) that you find on-line or in a book.

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.

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

First of all if you need help reading from standard input, or writing to standard output, see this link.

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 Dec 6 16:32:36 2023