Competitive Programming: Conquering a given problem
Last Updated :
28 Mar, 2016
Programming is the process of developing and implementing sets of instructions to enable a computer to do a certain task.The programming contests like ACM ICPC, Google CodeJam, and IEEE Extreme etc. are delightful playgrounds for the exploration of intelligence of programmers.
From knowing the contest at first to being at ACM ICPC Amritapuri Regionals, I have learnt a lot and would like to share some tips for the coders to tackle the contest problems.
During a real time contest, teams consisting of three students and one computer are to solve as many of the given problems as possible within 5 hours. The team with the most problems solved wins, where ‘solved’ means producing the right outputs for a set of test inputs (trivial and secret). Though the individual skills of the team members are important, in order to be a top team, it is necessary to make use of synergy within the team.
However, to make full use of a strategy, it is also important that your individual skills are as honed as possible. You do not have to be a genius as practicing can take you quite far. As far as feel, there are three factors crucial for being a good programming team:
- Knowledge of standard algorithms and the ability to find an appropriate algorithm for every problem in the set
- Ability to code an algorithm into a working program
- Having a cooperative strategy with your teammates
What is an Algorithm?
Algorithm is a step-by-step sequence of instructions for the computer to follow.
To be able to do something competitive in programming contests, you need to know a lot of well-known algorithms and ability to identify which algorithms is suitable for a particular problem (if the problem is straightforward), or which combinations or variants of algorithms (if the problem is a bit more complex).
Ability to quickly identify problem types
In all programming contests, there are only three types of problems:
- I haven't seen this one before.
- I have seen this type before, but haven't or can't solve it.
- I have solved this type before.
In programming contests, you will be dealing with a set of problems, rather than a single problem. The ability to quickly identify problems into the above mentioned context classifications (haven't seen, have seen, have solved) will be one of key factor to do well in programming contests. As far as my knowledge and repository, a problem is generally classified amongst given categories:
- Mathematics : Prime Number, Big Integer, Permutation, Number Theory, Factorial, Fibonacci, Sequences, Modulus
- Dynamic Programming : Longest Common Subsequence,Longest Increasing Subsequence, Edit Distance, 0/1 Knapsack, Coin Change, Matrix Chain Multiplication, Max Interval Sum
- Graph Traversal :Flood Fill,Floyd Warshal, MST, Max Bipartite Matching, Network Flow, Articulation Point
- Sorting : Bubble Sort, Quick Sort, Merge Sort, Selection Sort, Radix Sort, Bucket Sort
- Searching : Complete Search, Brute Force, Binary Search
- String Processing : String Matching, Pattern Matching
- AdHoc Problems: Trivial Problems
Ability to analyse your algorithm
You have identified your problem. You think you know how to solve it. The question that you must ask now is simple: Given the maximum input bound (usually given in problem description), can my algorithm, with the complexity that I can compute, pass the time limit given in the programming contest.
Usually, there are more than one way to solve a problem. However, some of them may be incorrect and some of them is not fast enough. However, the rule of thumb is: Brainstorm many possible algorithms - then pick the stupidest that works!
It is useful to memorize the following ordering for quickly determine which algorithm perform better asymptotically: constant < log n < n < n log n < n^2 < n^3 < 2^n < n!
Coding the Problem
Follow the principle KISS: Keep it Simple and Smart, keeping all versions working and stepwise refinement of code.
After you have coded with the best algorithm, matching time/space complexity and satisfying the test cases (sample test cases are trivial, so never measure code correctness according to them and try tricky cases too), then submit the solution – ‘ACCEPTED’
Identifying a tricky test case to get the opponent down is as important as solving the problem where your mind works more at the boundary conditions.
To summarise, these are some key points:
- Read all the problems, select the problem in order : easy to tough (if everyone is solving a selected problem, do have a look at it)
- Sketch the algorithms, complexity, conditions, data structures and tricky details
- Brainstorm other possible algorithms (if any) - then pick the stupidest that works
- Do all the Math and select the best algorithm.
- Code it, as fast as possible, and it must be correct.
- Try to break the algorithm - look out for boundary test cases.
The main mantra to succeed a problem is to keep calm, manage your time and have a strategic approach, rest your experience and practice plays the part.
 Keep
Practicing !!
This article is written by Vinay Garg.Â
Similar Reads
What are Ad Hoc Problems in Competitive Programming?
The Ad Hoc problems are problems that cannot be classified anywhere else in the categories with well-studied solutions since each problem description and its corresponding solution are unique. These problems don't fall under standard categories, there is no specific or general technique exists to so
5 min read
Competitive Programming - A Complete Guide
Competitive Programming is a mental sport that enables you to code a given problem under provided constraints. The purpose of this article is to guide every individual possessing a desire to excel in this sport. This article provides a detailed syllabus for Competitive Programming designed by indust
8 min read
Best Courses on Competitive Programming
Competitive programming has gone beyond being a niche interest. Has become a skill, for computer science enthusiasts. Being able to solve algorithmic problems is highly valued in the tech industry. Recognizing this demand various online platforms offer courses tailored to skill levels and learning p
5 min read
Learning the art of Competitive Programming
Learning the art of Competitive Programming How to begin with Competitive Programming?Top 10 Algorithms and Data Structures for Competitive ProgrammingHow to prepare for ACM â ICPC?How to prepare for Google Asia Pacific University (APAC) Test ?Remaining Ahead in Competitive Programming:Master in com
2 min read
25 Essential Concepts for Competitive Programming
Competitive Programming is a mental sport which enables you to code a given problem under provided constraints. The purpose of this article is to provide an overview of the most frequent tricks used in Competitive Programming. These 25 tricks will help you master competitive programming and solve th
15 min read
Competitive Programming vs General Programming
Programming enthusiasts face a crossroads - Competitive Programming or General Programming? This article sheds light on the distinctions between Competitive Programming vs General Programming, offering a quick guide for those navigating the coding landscape. Whether you're aiming for speed and preci
3 min read
String Guide for Competitive Programming
Strings are a sequence of characters, and are one of the most fundamental data structures in Competitive Programming. String problems are very common in competitive programming contests, and can range from simple to very challenging. In this article we are going to discuss about most frequent string
15 min read
How to become a master in competitive programming?
There are many people for whom programming is like a haunted dream. Programming is nothing but an art of talking with machines and telling them what to do, when to do, and why to do. Most of the students hear this word in high school. For many of them programming starts with âCâ and ends at âCâ. The
4 min read
Dynamic Programming in Game Theory for Competitive Programming
In the fast-paced world of competitive programming, mastering dynamic programming in game theory is the key to solving complex strategic challenges. This article explores how dynamic programming in game theory can enhance your problem-solving skills and strategic insights, giving you a competitive e
15+ min read
Mathematics for Competitive Programming Course By GeeksforGeeks
Mathematics forms the foundation of problem-solving in Competitive Programming (CP). Mastering key mathematical concepts is crucial for approaching algorithmic challenges effectively. If you're an aspiring competitive programmer or someone who wishes to enhance your problem-solving skills, this Math
3 min read