Competitive Programming with C++ : Part 1

Rajendra Prajapat
Dev Genius
Published in
3 min readMay 30, 2020

--

If you are here, that means you want to start Competitive programming, or you heard this word from somewhere. There are two ways to learn to program: one is to do some projects, and another is to start competitive programming. In projects, we learn by implementing solutions to real-world problems, whereas, in competitive programming, we learn by implementing various scenarios, given in a problem statement. In competitive programming, you write efficient and optimized code for the given problems on a platform in a given time in a programming language of your choice. In this blog, we would be discussing competitive programming.

Competitive Programming has two parts: designing the algorithms and implementing the algorithm. So before dive into Competitive programming, let’s discuss what are the algorithms first.

What are the algorithms?

In simple words, the algorithm is a sequence of well-defined tasks to complete a significant task. For example, we have some items with a price tag. Now we want to find the item at the least price. For this, we can write the algorithm as follows-
First, we pick-up an item and put it in our beg, and then check the price of the next item, and if the item has a lower price than the product we have in our beg, we replace it with the new item, otherwise, check for the price of the next item.

Pseudo-code for this algorithm can be written as follows:

1. Pick up the first item
2. Choose a next item
3. If the price of the item is lower than the price of the item in our beg, then replace it with a new item.
4. Go to 2 until all the items are not checked.

Designing of the Algorithms

In competitive programming, writing an algorithm is not enough, But it requires writing an efficient algorithm that solves a well-defined computational problem. An algorithm to solve a given problem may be the combination of multiple well-known algorithms or methods. The design of the algorithm requires good problem-solving skills as well as mathematical skills.

Implementing the Algorithms

Once we come up with an algorithm that solves the problem, the next step is to correctly implement it, which requires good programming skills. Our solution to a problem is evaluated by running our program on a large number of test cases. In competitive programming, the code should be short so we can implement it in a short period because, in Competitive Programming, implementation time is more important to get a good score.

Which Programming Language is used in Competitive Programming?

You can use any programming language to test your Competitive Programming skills. The languages supported by most of the platforms are C, C++, Python, Java, and Kotlin. C++ is the most popular programming language for competitive programming because of its speed, and extensive library support such as STLs and Algorithms. I also prefer C++ for competitive programming.

Which Platform is best for Competitive programming?

There are various platforms are available for the Competitive Programming. The most popular platforms in India are Codechef, Codeforces, Atcoder, HackerRank, HackerEarth, LeetCode. If you are new to programming, you should attend beginner contests on AtCoder, division-3 contests on Codeforces, and long-contest on Codechef. The long-contest on CodeChef is a great way to learn algorithms. In this contest, you are provided 6–7 problems for 10 days where you are allowed to use the internet or books.

Why you should do Competitive Programming?

If you love challenges and programming, then Competitive Programming is for you. If this motivation is not enough for you to start Competitive Programming, let me give you the other, If you are good at Competitive Programming, you can easily clear the technical rounds of the hiring process.

Competitive Programming teaches us to solve a problem by multiple approaches in a short time. It improves our problem-solving skills, debugging skills, and mathematical skills. When you start competitive programming, you will enjoy this game.

In part 2 of this blog, we will start with the basics of C++ programming for Competitive Programming.

--

--

SDE@Sharechat | Competitive Programmer | MERN Stack Developer| Interested in Computer Networks, CyberSecurity, and Machine Learning field