Skip to content

COS 102 / Week 01

Roadmap to Problem Solving

What a problem-solving strategy is, how to tell a well-defined problem from an ill-defined one, the four steps of solving by code, and the core techniques.

Subjects
Problem solving / Algorithms / Heuristics

Most programming courses open with syntax. This one opens with the problem. Write the solution in plain language first, then let the code follow. Syntax is the easy part once the thinking is right.

What a problem-solving strategy is

A problem-solving strategy is a plan you use to find a solution or get past a challenge. Different strategies carry different action plans, and each one gives you steps to follow so you can resolve a problem in a repeatable way.

Solving a problem well takes three things: identify the problem, choose the right process to approach it, and follow a plan suited to the specific issue in front of you.

Creativity matters here too. Creativity is the ability to look at a task in a different way, to use intuition to form new ideas. It lets you approach a problem from every angle instead of marching down one linear path, and that is often what separates a workable solution from a stuck one.

Two kinds of problems

Not every problem is shaped the same way, and the shape decides how you attack it.

Well-defined problems

A well-defined problem has a clear starting point, clear rules, and a clear goal. The problem space is fully specified: the initial state, the set of operators or moves you are allowed, and the goal state. The Tower of Hanoi is the classic example. You know exactly where you start, what moves are legal, and what finished looks like.

Ill-defined problems

An ill-defined problem has no clear goal, no obvious path, and no single expected answer. It is ambiguous, open to several readings, and you often cannot even tell when you have finished. "Write a computer program for music" is ill-defined: it names neither a starting state nor a goal. Much of the real work of problem solving is turning an ill-defined problem into a well-defined one before you write any code.

The four steps of solving by code

  1. Analyse the problem. Understand what is being asked and what counts as a correct answer before doing anything else.
  2. Develop an algorithm. Write the solution as ordered steps, in plain language or a flowchart, with no code yet.
  3. Code it. Translate the algorithm into a program.
  4. Test and debug. Run it, find where it disagrees with the expected result, and fix it.

Core techniques

Trial and error. Try one solution, rule it out if it fails, try the next. A broken printer is the everyday example: check the ink, then the paper tray, then the cable. It is rarely the fastest method, but when the options are few it is a reasonable one.

Algorithm. A step-by-step formula that, followed exactly, produces a correct result every time. Precise and repeatable.

Heuristic. A general framework or mental shortcut, a rule of thumb. Unlike an algorithm it does not guarantee the right answer, but it gets you to a good one quickly when an exact method would cost too much.

Means-end analysis. Break the gap between where you are and where you want to be into smaller steps, and pick an action that closes part of it. The Tower of Hanoi solves cleanly this way under three rules: move one disk at a time, move only the top disk of a stack, and never place a larger disk on a smaller one.

When you are stuck

A few moves that reliably help: use past experience with similar problems, bring in someone to facilitate, build a decision matrix to compare options, ask your peers, and step away from the problem for a while so you can return to it fresh.

All lessons