Learning to program means learning how to solve problems using code. That’s why having good, strong problem solving skills can make a huge difference to your career.
Inspired by Anton Spraul’s book “Think like a programmer”, I decided to write this article and outline some techniques, which will help coders learn problem solving in a systematic way, instead of learning by trials and errors.
Always Have a Plan
Many of us think, that planning is a waste of time, as our plans don’t always turn out perfectly. But to solve the problem, at first we need to construct the solution path in our mind, then implement it in code.
Military leader, the Prussian Helmuth von Moltke, famously said that “no plan survives first contact with the enemy”. But no army can succeed without planning and organization. Through planning, a general learns what his army’s capabilities are, how the different parts of the army work together, and so on.
Planning is essential part of problem-solving, as you consider all possible options and select the best for your problem. Those who struggle to develop a single plan don’t make good problem solvers.
Redefine the Problem
When facing a problem, one of the best first steps is redefining the problem. Paraphrase it, turn the problem on its head, redirect the focus or try to place emphasis on different words and phrases.
Sometimes when you think about the problem as a difficult one, it turns out to be simple, when you just paraphrase it. Restate the problem in as many different ways as you can think of. This technique opens our mind to alternatives.
Divide the Problem
Even at school, our teachers taught us that in order to solve math problems we should divide them into smaller parts. It’s easier to deal with each part separately, than struggle understanding the whole problem at once. The rule still remains the same in coding. Break down a problem into two or more sub-problems of the same or related type, until these become simple enough to be solved directly.
Start with What You Know
It’s always easy to solve what you know, then pass to unknown parts. Why? As when starting from difficult ones, you get frustrated and confused quicker.
Experimenting is vital in programming. In order to get better, you should keep on practicing your skills, and sometimes you need to try several times to find the best solution to the issue. If you don’t know the result beforehand, it’s better to experiment, than guess in uncertainty.
Don’t Get Frustrated
Golden rule, and not only in programming!
When you suffer trying to solve a problem, you can easily get frustrated, which will reduce the efficiency of your work.
So my advice to you: Have a break, allow your brain to relax and get out of the mental rut.