CPT121 - Introduction To Problem Solving - Module 1 - Unit 2
CPT121 - Introduction To Problem Solving - Module 1 - Unit 2
SOLVING
Objectives
3
The Process of Problem Solving - Introduction
Introduction
Regardless of the area of study:
The problems,
can come from any real-world problem or
5
The Process of Problem Solving - Introduction
A Simplified Uni-
Processing
Computer System
6
The Process of Problem Solving - Introduction
9
The Process of Problem Solving - Computer as a
Model of Computation
In solving a problem, there are some well-defined steps to be
followed.
Output: output the answer to either the monitor, printer, USB flash or
10
hard disk … or a combination of any of these devices.
The Process of Problem Solving - Computer as a
Model of Computation
It can be noted that the problem is easily solved by simply:
11
The Process of Problem Solving - Understand the
Problem
Understand the Problem
12
The Process of Problem Solving - Understand the
Problem
One also needs to know
15
The Process of Problem Solving - Understand the
Problem
Also, there is a formatting issue.
Should the output be a whole or real number or a letter grade?
16
The Process of Problem Solving - Fomulating a Model
Formulating a Model
The next step is to understand the processing part of the problem.
Many problems are broken down into smaller problems
that require some kind of simple mathematical computations in order
to process the data.
From the given example, the average of the incoming grades is
to be computed.
Thus, a model (or formula) is needed for computing the average
of a bunch of numbers.
such a “formula”, needs to be developed if does not exist.
17
The Process of Problem Solving - Fomulating a Model
In order to come up with a model, we need to fully understand the
information available to us.
Assuming that the input data is a bunch of integers or real
numbers:
x1, x2, ... , xn, representing a grade percentage,
Develop an Algorithm
After the formulation of a model,
It is time to come up with a precise plan of what the computer is
expected to do.
Definition: Algorithm is a precise sequence of instructions for
solving a problem.
Some of the more complex algorithms may be considered
Randomized algorithms or non deterministic algorithms,
where the instructions are not necessarily in sequence and may not even
have a finite number of instructions.
19
The Process of Problem Solving - Develop an Algorithm
In this course, the above definition will apply for all algorithms
that will be discussed.
To develop an algorithm,
the instructions must be represented in a way that is
understandable to a person who is trying to figure out the
steps involved.
21
The Process of Problem Solving - Develop an
Algorithm
Although flowcharts can be visually appealing, pseudocode is often
the preferred choice for algorithm development because:
It can be difficult to draw a flowchart neatly
Pseudocode fits more easily on a page of paper.
It can be written in a way that is very close to real program code, making
it easier to write the program
Pseudocodes vary but there are some common control structures, these
features are shown along with some examples, in the slides that follow:
22
The Process of Problem Solving - Develop an
Algorithm
1. Sequence Structure:
4. ……
23
The Process of Problem Solving - Develop an
Algorithm
2. Condition Structure
then plug it in
24
The Process of Problem Solving - Develop an
Algorithm
REPEAT
get a new light bulb
put it in the lamp
Until lamp works or no more bulbs left
REPEAT 3 times
Unplug lamp
Plug into different socket
25
The Process of Problem Solving - Develop an
Algorithm
4. Storage Feature
If bulb works
then goto step 7
26
The Process of Problem Solving - Develop an
Algorithm
Further Example
Algorithm: DisplayGrades
It would be wise to run through the above algorithm with a real set
of numbers.
Here is an instance:
Given n = 5, x1 = 95, x2 = 55, x3 = 43, x4 = 60, x5 = 71
29
Program examples
the next task is to make sure that it solves the problem that it
was intended to solve and that the solutions are correct.
When a program is run and all is well, you should see the
correct output.
31
The Process of Problem Solving - Test the Program
33
The Process of Problem Solving - Test the Program
Debugging is often:
34
The Process of Problem Solving - Evaluating the
Solution
Evaluating the Solution
problem; perhaps
Formulating a Model
Developing an Algorithm
Formulating a Model
Developing an Algorithm
40