Problem Solving Process
Designing a solution to a problem involves 6 steps:
  1. Analyze the problem
  2. Plan the algorithm
  3. Desk-check the algorithm
  4. Code the algorithm into a program
  5. Desk-check the program
  6. Evaluate and modify the program ( if necessary).

Step 1 − Analyzing the Problem

It is essential to understand a problem before creating a solution to it. During analysis, the goal (output) to solve the problem and the items needed (Input) to achieve the goals are determined. An IPO (Input, processing, and output) chart is used to organize and summarize the results of a problem analysis.

Example: of an IPO chart
Scenario: write a program that calculates and displays the circumference of a circle given the radius (r). The circumference is computed as 2Pi(r).
Based on this scenario, the following IPO Chart can be designed to help design a programmer to solve the above problem. Note that Processing Item is a variable that is needed to hold a value while processing.

...
Figure i

Step 2 − Planning the Algorithm

An Algorithm is a set of instructions that will transform the problem’s input into a output. It can be written either as pseudocode or a flowchart. It is recorded in the Processing column of the IPO chart. Pseudocode is short English statements to plan an algorithm.

Example 1: An algorithm to calculate the circumference of a circle

  1. Get the radius
  2. Calculate the Circumference of the circle by using the formula: 2 * PI * radius
  3. Display Circumference of Circle

Example 2: An algorithm to print "passed" if the students marks is greater than 50 and prints "failed" otherwise

  1. If student's mark is greater than or equal to 50 then
  2. Print "passed"
  3. else
  4. Print "failed"

Example 3: An algorithm to determine the average marks for the class size of 10

  1. Set total to zero
  2. While grade counter is less than or equal to ten
  3. Input the next grade
  4. Add the grade into the total
  5. endwhile
  6. Set the class average to the total divided by ten
  7. Print the class average.

A Flowchart uses standardized symbols to design the algorithm.

Figure 2.2
Figure ii
Example of a flowchart which calculates the circumference of a circle
Figure 2.3
Figure iii

Step 3 − Desk-check the algorithm

Desk-checking (also called hand-tracing) is checking an algorithm by hand (e.g. using pen and paper) to verify its correctness. A set of sample data is chosen and the expected output value is manually computed.

A desk-check table is used while desk-checking an algorithm. It should contain valid and invalid data

  • Valid data: data that the algorithm is expecting the user to enter
  • Invalid data: data that the algorithm is not expecting the user to enter. Users may make mistakes when entering data so your program should handle these errors appropriately.
Example of a desk-check table:
Table i
Sample Radius Circumference
1 2 12.57
2 5.5 34.57
3 0 Radius should be positive
4 -5 Radius should be positive
5 m Radius should be numerical

Step 4 − code the algorithm into the program

In this step, each unique input, processing, and output item in the IPO chart is given a descriptive name, data type, and (optionally) an initial value. Then the algorithm is written using a programming language.

Step 5 − Desk-Check the program

This step is performed to ensure that the instructions were translated correctly. The program is desk-checked using the sample data used to desk-check the algorithm in step 3. The results of both desk checks should be the same.

Step 6 – Evaluate and Modify the Program

This is the final step in the problem-solving process where errors (known as bugs) are fixed which were found while evaluating the program in step 5.

The process of locating and fixing errors is called debugging. There are two types of bugs: syntax errors and logic errors.

  • Syntax errors are caused by violating the rules of a programming language. Compilers can detect these errors.
  • Logic errors are caused by applying incorrect logic in the program. The compiler is not able to detect these types of errors and can be hard to identify. E.g. entering instructions in the wrong order.