Introduction to Competitive Programming
Competitive programming is a mind-sport where participants solve algorithmic problems under time constraints. There is an emphasis on logical (mostly mathematical) thinking and combining solution steps to an efficient algorithm. If you ever participated in other competitive mind-sports (math contests, chess tournaments, etc.) you will feel right at home here. It’s also not enigmatic for new-comers, as there are a wide variety of problems in all difficulty ranges available (for free!) to ease you in. We will get to those shortly. But first, let’s answer the question of “why?”.
Why Competitive Programming
-
Algorithmic Thinking: It sharpens your ability to think algorithmically and develop strong problem-solving intuition. Converting ideas into efficient computer algorithms can be challenging at first, but with consistent practice, you’ll see significant improvement.
-
Better Programming: Following from the previous point, thinking it terms of computer algorithms makes you a better programmer overall. Also, you will encounter programming techniques, tricks and hacks that academics don’t generally cover.
-
Problem Solving: Breaking problems down into small parts, making observations and understanding the dynamics of a system/scenario, first principle thinking are integral parts of being a good thinker. These are universally useful traits that will help you even beyond the bounds of programming and academia.
-
Job Prospects: Many tech-interviewers assess programmers with contest-style problems. Performing well in those can greatly enhance your chances of being hired.
Getting Started
So, how to get started? Not everyone will have the same methods or trajectory. There are so many resources these days, it is easy to get overwhelmed. Here is my advice to stop you from doing that,
-
Programming Language: Being comfortable with the syntax is important. Choose a programming language and stick to it. You don’t have to become a master at it, just make sure you are comfortable. If you have trouble choosing, most commonly used language is C++. Many people also use JAVA or python. There is no objectively best programming language.
-
Start Solving: Yes, that is correct! You don’t need to know complex graph algorithms or segment trees or dynamic programming tricks to get started. Just look for easier problems and start solving. Initially, you need to build the habit of reading problems deeply and understanding what’s going on. Many problems are verbose and it can be hard to decipher the requirements at first. That is why it is important to look at as many problems as possible. Don’t spend too much time on any one if you’re a complete beginner. Spend some time thinking for yourself before looking at others’ solutions. How much time you should spend depends on you, and there is no answer that will work for everyone. Make sure you fully understand what the problem is asking for before you stop.
-
Learn New Concepts on The Fly: Slowly learning new topics as you encounter problems that require them is the best way to make progress in my opinion. For example, if you’re completely new, maybe you encounter a problem that requires sorting an array. Then, it would be best to finally check which library in the language of your choosing allows you to do that and how. If you’re a bit more advanced, maybe you will finally encounter a graph or DP problem. You should then read up on how they work. This is how your repertoire of tools and knowledge will expand. Computer science is vast, and many of the algorithms or data structures used in intermediate to advanced problems are research papers from ’60s, ’70s, ’80s (some more recent ones also exist). Learning ALL the prerequisites before starting is therefore, impossible.
How to Practice
You will find many guides on the internet that focus on how to increase ratings. Although they generally offer good advice on how to improve, it can be misleading. Your worth as a programmer is not tied to your rating. It is more important that your problem-solving skills improve because, ratings are just an approximate reflection of that.
Some problems require mathematical thinking, some require common patterns, some require a particular data-structure. All of these are patterns and the more problems you solve, the more familiar you will be with a wider variety of patterns. A wider repertoire means a wider toolkit which ultimately means you’re a better problem solver! Here are places you can look through to encounter problems.
- CodeForces: Hosts regular contests and has a rich archive of problems. Has more math oriented problems.
- AtCoder: Regular contests and a great problem library. Has more implementation-heavy problems.
- CodeChef: Contests and problem archive.
- Ultimate Topic List by YouKn0wWho: A compilation of most topics you will encounter in ICPCs and IUPCs.
- CP-31 Sheet: A curated list of CodeForces problems from various rating ranges.
As you encounter newer topics or techniques, try to understand the underlying reason and mechanism for employing those techniques or patterns. Only then will you be able to solve similar problems in the future.
Closing
Competitive programming is hard. And as you get better and better, you will start to realize you are pushing yourself beyond your limits. This is as good as it is mentally straining. Progress will slow down, you will get many WA (wrong answer) and TLE (time limit exceed) verdicts. Don’t be detered. It is part of the process. Frustration is an integral part of any sport and the persevering through it is what separates an average athlete from a great one. Ultimately, it’s about becoming better than yourself. And that feeling is quite exhilarating.