Question

More specifically, how to study competitive programming, but starting with the notes.

Some background information: So I am new to programming. I noticed that competitive programming is a lot like math competitions. These are real world problems and just remembering a few for an exam is not like the industry. For example, mathematics is not just a "learn and regurgitate" discipline. More specifically, everyone knows something about quadratics, but if I ask you to solve this problem:

Two different positive numbers a and b each differ by their reciprocal by one, what is a+b?

The information you learn about quadratics starts to become useless without knowing how to apply it. For example, going through this problem I might do:

Let X be a number that differs from its reciprocal by one. This means that X+1=1/X and X-1=1/X (the reciprocal of X, being 1/X). Then I would turn both equations into a quadratic: X^2+X-1=0 and X^2-X-1 equal zero. I would then use the quadratic formula and solve for X for both equations. For the first equation, you would get: (1+-sqrt(5))/2 and for the second: (-1+-sqrt(5))/2 notice, +- means (plus or minus). I would take both the positive of both and add them together getting sqrt(5)=a+b.

For the notes, if I had to search them up, or realized something important I might say something like: Big Idea 1: When there are multiple terms like "a" and "b", generalize or reduce to one term. Big Idea 2: If the problem mentions something about the "positive/negative" of two numbers try to turn/relate the problem to a quadratic.

These would be good notes.

However, let's say you are doing a problem in Java like:

Write a method in Java that returns a boolean if the parameter is a palindrome. For example, isPalindrome(1221) should return true since 1221 is the same backwards or frontwords. Similarily, isPalindrome(-1221) should return true because negative numbers can be palindromes.

Now, after some time I can't figure out how to do it, so I search up for the answer and get:

public static boolean isPalindrome(int number) {

    int reverse = 0;
    int numberClone = number;

    while(numberClone != 0) {
        int lastDigit = numberClone % 10;
        reverse = reverse * 10;
        reverse += lastDigit;
        numberClone /= 10;
    }


    if (number == reverse) {
        return true;
    } else {
        return false;
    }
}

When seeing a new programming solution like this, how can I find the technique the person used and generalize it to all instances of when I should apply this technique?

Was it helpful?

Solution

Competitive programming is very different than the programming you will see in industry. All you see about making code readable and maintainable becomes a waste of time.

Competitive programming is also quite different from maths. Yes, there is a component of problem solving (which is a bit more mathsy), but there is also the implementation part, where you need to train for speed when typing and the general code writing.

For example, you might devise a solution to a problem that requires sorting. Then, it is a matter of using the right language features to do the sorting.

From experience, I'd say that you need to get accustomed to the language, then learn programming techniques and tricks to solve problems. Then, you build the speed by practicing and reading solutions.

When taking notes, 2 things are relevant: the algorithm itself and possibly interesting implementation tricks that can help you speed up writing the code. The rest comes from the knowledge of the language.

OTHER TIPS

This just my opinion and take on your question.

Mathematics is definitive with objectivity. Programming on the other hand is defined subjectively based on the problem being solved. The “big idea” can be anyone’s point of view.

In general, however your classes should follow single responsibility principal. Your methods short and concise.

In programming you look at the business’ goals and the problems businesses need resolved. You layout all the business rules. Then the most important step once all the business rules are known is to figure out who is responsible for the rules and of those rules, which is ones will be subject to change the most and who decides will make the changes. Then gather rules that will change the most and with the fewest people possible who will determine a change and group all that business rule-knowledge into single classes doing specific things. That way when change happens it impacts single classes and impacts a single component or library.

With that comes the challenge that companies, and corporations must take ownership and responsibility over the application we programmers build for them.

So where is the big idea to be found in all this?

It depends from company to company, from one goal to the next.

Each programmer brings to the table their own experience and subjective point of view. There really are no hard set of rules, but rather principals and guidelines.

Licensed under: CC-BY-SA with attribution
scroll top