Uploaded by Leslene Laing

Lesson 1 - Outline the steps in problem solving

Outline the steps in problem solving.
Section 2: Problem-solving and program design
Objective 2.1: Outline the steps in problem solving.
Objective 2.2: Decompose a simple problem into its significant parts.
Content Definition of the problem; propose and evaluate solutions; Determination of the most
efficient solution; develop and represent algorithm; test and validate the solution; decompose
a problem into input, processing, output and storage.
The steps in problem solving
The steps in problem solving are:
1. Definition of the problem
2. Propose and evaluate solutions
3. Determination of the most efficient solution
4. Develop and represent algorithm
5. Test and validate the solution
Definition of the problem
Defining the problem is the first step towards solving a problem. It is the most important step
since it leads to a clearer understanding of what is given and what is required. If the
programmer does not fully understand what is required, then he/she cannot produce the
desired solution. This step involves decomposing the problem into three key components:
1. Inputs: what is given (source data)
2. Outputs: the expected results
3. Processing: the tasks/actions that must be performed
To do this, a defining diagram is used. A defining diagram is a table with three columns labeled
to represent the components.
Inputs can be identified by the keywords that precede them. These are: GIVEN, ENTER, READ,
Outputs can be identified by the keywords: PRINT, DISPLAY, FIND, PRODUCE, or OUTPUT.
Processing can be determined by asking;
“What do I have to do with the inputs in order to produce the desired output?” The
actions/tasks determined must be listed in a logical sequential order.
Given two numbers find and print their product.
Defining diagram:
2 numbers say num1, num2
1. Read two numbers
2. Find the product
3. Print the product
Proposing and Evaluating Solutions
Proposing a solution
The second step in solving a problem is ‘Proposing and Evaluating Solutions’. After defining the
problem, you would know what needs to be done. In this step, you figure out how to do it,
bearing in mind that a problem can have many different solutions. Initially, go through each
step of the solution manually (by hand) using sample input data to see if the solution provides
the desired outcome. Then review it to see how you can make it more efficient. After
completing the manual solution to the problem the next step is to write the solution as a
sequence of instructions.
Read first number, call it num1
Read second number, call it num2
Multiply num1 by num2
Print product
Objective 2.3: Distinguish between variables and constants
In processing data, values that are manipulated need to be stored in a memory location.
Because of the large number of storage location in memory, we need to have an identifier to
label each location. Depending on if the value changes during the execution of the instructions,
it is called a variable. If the value does not change it is called a constant.
Choosing Identifier Names
Choose names that reflect the kind of data that is being stored. It helps any reader to
understand the solution better, if the identifier reflects what they store. For example, the
variable name product indicates that the value stored in that memory location is a product. If
instead, X was used, this does not convey the contents of that memory location to the reader of
the solution, and it will make debugging and program maintenance more difficult. Most
programming languages have strict rules regarding identifier names, for example, in Pascal,
they must begin with a letter or underscore; they can be a combination of letters and digits or
underscore and the length cannot exceed 31 characters.
Objective 2.4: Use appropriate data types
Each piece of data stored in memory is of a specific data type. In programming there are five (5)
basic data types.
Data Type
Positive and negative whole numbers including zero
23,-45, 0
All numbers including fractions
15.7, -19.25, 8
Any key on the keyboard
‘A’, ‘z’, ‘8’, ‘?’
Characters put together
True or False
‘Hello world’, ‘Marcus’