Problem solving

As a programmer most of the time we are solving problems. We get a problem and we need to be the ones that figures out the solution for that problem. Instead of just trying something out to solve the problem we will here give you a framework for solving problmes!

Understand

The first part of solving a problem is understanding the problem. Here are two quotes that stress the importance of understanding your problem

“If you can’t explain something in simple terms, you don’t understand it.” — Richard Feynman

“If I had an hour to solve a problem I'd spend 55 minutes thinking about the problem and 5 minutes thinking about solutions.” - Albert Einstein

So we need to understand the problem before trying to solve it. It makes intuitive sense but what we see is that novice students often spend to little time understanding. To help you understand a problem try some of these methods

  • Write the problem down

  • Doodle a diagram

  • Tell someone else about your problem

  • Or use rubber duck debugging (this technique has helped me many many times)

Plan

When we truly understand the problem as well as we can, we need to plan for fixing the problem.

Planning gives your brain time to analyze the problem and properly process the information. It is a task that is not done often enough especially among novice programmers. Novice programmers have a tendency to just start solving a problem. This typically affect the solution that in turn has not been structured well/thought through/have problems.

So how should a plan be made then? It's up to you. Typically just writing down in steps how you are going to solve the problem is sufficient. Another helpful tool when planning writing some software is writing pseudo code

Divide

By this stage the you should have a clear understanding of the problem and an overall plan for how you will fix the problem.

Now we need to divide the problem into smaller subproblems.

Dividing a problem into smaller subproblems can help solve a problem becuase smaller subproblems are easier to fix than larger problems. When you have solved all the subproblems, connect the dots.

“If I could teach every beginning programmer one problem-solving skill, it would be the ‘reduce the problem technique.’

An example could be to figure out how many ping pong balls can fit in a car. Let's first figure out how many ping pong balls can be in a qubic meter using a divide tactic 👇

  • Hmm that's tough but how many can be in a qubic decimetre. Probably around 9 or 10

  • So in a cubic meter there would be 10.000 ping pong balls

  • How many cubic meter fits in a car? Maybe around 30, depends on the size.

  • Okay so 30 * 10.000 is 300.000 ping pong balls in a car

Exercises

  • Hvor mange frisører er der i københavn?

  • Hvor mange myrer er der i en koloni?

  • Hvor mange klaverstemmere er der i Tyskland?

  • What angle does an hour hand describe in 20 minutes?

  • Two circles have radius equal to 2 cm and 3 cm. The distance between their centres is 4 cm. Do they interact?

  • A can of kerosene weighs 8 kg. Half the kerosene is poured out of it, after which the can weighs 4.5 kg. What is the weight of the empty can?

  • What time is it now if the time which passed since noon constitutes a third of the time that remains until midnight?

Harvard questions:

Harvard entry question
Oxford question
Oxford question 2

Last updated

Was this helpful?