Information Technology Topic

Steps in Problem Solving

  1. Read notes
  2. Flashcards
  3. Quiz
  4. Confident

Study focus - 3 things

  1. The five steps in order: define the problem; propose and evaluate solutions; choose the most efficient; develop and represent the algorithm; test and validate the solution
  2. Efficient means fewer steps, less time or less memory, but only plans that already give correct answers are compared
  3. Work out the expected answers before testing, and go back to an earlier step whenever the results do not match

Visual notes

The five problem-solving steps
A flow of 5 boxes joined by green arrows pointing down. Step 1, define the problem: what goes in, what must come out. Step 2, propose and evaluate solutions: list ideas, then judge each one. Step 3, choose the most efficient solution: the best plan that works. Step 4, develop and represent the algorithm, as pseudocode or a flowchart. Step 5, test and validate the solution by comparing with predicted answers. A dashed brown arrow leaves the right side of step 5 and returns to step 4, labelled Not right? Go back.

The steps run in order from 1 to 5, and when a test fails you go back to an earlier step.

Section 1Why solve a problem in steps?

A computer does exactly what it is told, so the instructions have to be right before it starts. Typing code first and thinking later is like laying blocks for a house in Portmore before anyone has drawn the plan. Problem solving gives you a plan of five steps: define the problem; propose and evaluate solutions; choose the most efficient solution; develop and represent the algorithm; test and validate the solution. Here's the trick: the first three steps happen on paper, before any program exists.

Section 2Step 1: define the problem

Say exactly what has to be solved. What must the user give the computer (the inputs)? What must come back (the outputs)? What rule links them? A computer cannot think for itself, and its commands have to cover every possibility. So the definition has to look at every case that could come up. Ask the awkward questions now: what if the quantity is zero? What if nothing is entered? A good definition can be read by someone else and understood. For a Mandeville hardware shop: 'Input: the number of zinc sheets wanted. Output: the bill. Rule: every sheet costs the same.'

Section 3Step 2: propose and evaluate solutions

There is nearly always more than one way to solve a problem. Write down two or more possible solutions in rough words. Then evaluate each one: does it give the right answer, and how much work does it need? Try each idea on a small example whose answer you already know. An idea that gives the wrong answer on the example is dropped straight away, however neat it looks. Watch out: evaluating is not choosing. Step 2 is about judging each proposal. Choosing comes in step 3.

Section 4Step 3: choose the most efficient solution

Efficient means getting the job done with the least effort from the computer: fewer steps, less time or less memory. Count the operations in each plan that works and compare. At a Portmore school tuck shop, Plan A adds each of 40 receipts to a running total as it is entered: 40 operations. Plan B writes all 40 receipts on a list first and then adds them up: 40 writes and 40 additions, 80 operations. Both give the right total, so Plan A is the more efficient. Easy to mix up: a short plan that gives wrong answers is not efficient, it is just wrong. Only plans that already work are compared for efficiency.

Section 5Step 4: develop and represent the algorithm

An algorithm is a set of steps that achieves the result you want. Developing it means turning the chosen plan into exact steps, in order, that a computer could follow. Representing it means writing it down in a standard form: pseudocode (English-like instructions using words such as Input, Store and Display) or a flowchart (boxes and arrows). Each has its own topic. For the average of three marks the pseudocode is: Input mark1, mark2, mark3 Store (mark1 + mark2 + mark3) / 3 in average Display average

Section 6Step 5: test and validate the solution

Testing means running the algorithm on test data and comparing what it gives with answers you worked out beforehand. Predict first, then run. If you predict afterwards, you can talk yourself into believing whatever the algorithm shows. For the averaging algorithm, the test data 60, 70 and 80 should give 70, because 210 divided by 3 is 70. If it shows 210, the test has found a fault. Validating means checking that the finished solution really solves the problem defined in step 1, not just that it runs. Use more than one set of test data, because one passing test does not prove the solution is right.

Section 7The steps are not a one-way street

When a test fails you go back: correct the algorithm (step 4), rethink the plan (steps 2 and 3), or even fix the problem definition (step 1). Then you test again. The picture shows this with the dashed arrow looping back from the last step. Here's the trick: the earlier a mistake is caught, the cheaper it is to fix. A wrong idea caught in step 2 costs one crossed-out line. The same mistake caught after the program is finished means changing a lot of work.

Examples

A student is building a program that works out a student's average mark. These actions happen in a mixed-up order: (i) Run the algorithm on marks 60, 70 and 80 and compare with 70. (ii) Decide that the inputs are three marks and the output is their average. (iii) Pick the plan that needs the fewest operations. (iv) Write the chosen plan in pseudocode. (v) List two or more possible plans and judge each one. (a) Put the actions in the correct order. (b) Name the step that each action belongs to.

(a) The correct order is (ii), (v), (iii), (iv), (i). (b) (ii) is step 1, define the problem: it names the inputs and the output. (v) is step 2, propose and evaluate solutions. (iii) is step 3, choose the most efficient solution. (iv) is step 4, develop and represent the algorithm, because pseudocode is one way to represent it. (i) is step 5, test and validate the solution, because the algorithm is run on test data and compared with the predicted answer, 70. Here's the trick: each step needs the one before it. You cannot judge plans until the problem is defined, and you cannot test an algorithm that has not been written.

A teacher in Mandeville wants the average of three test marks. Two plans are proposed. Plan A: add the three marks and divide by 3. Plan B: add the first two marks and halve the result, then add the third mark to that and halve again. The test data is 60, 70 and 80. (a) Work out the predicted average. (b) Evaluate both plans on the test data. (c) Count the operations in each plan and choose one. (d) A first draft of the algorithm shows the sum of the three marks instead of the average. Say what it shows for the test data and what the tester should do.

(a) The predicted average is (60 + 70 + 80) / 3 = 210 / 3 = 70. (b) Plan A gives 210 / 3 = 70, which matches. Plan B gives (60 + 70) / 2 = 65, then (65 + 80) / 2 = 72.5. That does not match 70, so Plan B is wrong and is rejected at once. (c) Plan A uses 2 additions and 1 division, which is 3 operations. Plan B uses 2 additions and 2 divisions, which is 4 operations. Plan A is both correct and shorter, so it is the most efficient plan that works. Choose Plan A. Efficiency would only matter between two plans that were both correct. (d) The draft shows 60 + 70 + 80 = 210, but the predicted answer is 70. The results differ, so the test has found a fault. The tester goes back to step 4, adds the division by 3, and tests again.

Now let's water it

Session runs notes to flashcards to quiz back-to-back.

Where this comes from