Professional Documents
Culture Documents
Solving
Presented
by Sheryl Robinson
Solving a problem on a
computer involves the
1. Definition of the problem
following
activities:
2. Analyze
the problem.
3. Propose and evaluate possible
4.
5.
6.
7.
8.
solutions
Develop an algorithm (a method) for
solving the problem.
Test and validate the algorithm.
Implement the algorithm( ie Writing
the program for the algorithm)
Run the program
Document and maintain the program.
Definition of the
problem
One has to look
carefully and identify
Analyze the
In this stepproblem.
you would :
identify the inputs to be used or
required (INPUT)
Identify the processing required to
achieve correct output (PROCESS)
Identify values to be stored if any
(STORAGE)
Identify required outputs (OUTPUT)
Analyze the
Problem
This step helps
you to take a complex
Narrative
A narrative is a representation of an
algorithm Algorithm
where each instruction is written in
everyday language
Problem statement: see question#3
Step1: Start
Step2: Get the two numbers
Step3: Add the numbers
Step4: Store the results in Sum
Step5: Display sum
Step6: Stop
IPO Chart
Input
Processing
Output
A,B
Sum = A+ B
sum
Propose and
evaluate possible
This step involves examining all the
solutions
possible solutions
to the problem and
then select the best one ,given the
resources available (e.g.. time)
Develop an
An algorithm
is a finite number of accurate,
algorithm
unambiguous steps that solve a problem
Characteristics of a
good
algorithm
The number of steps must be finite
The steps must be precise
The steps must be unambiguous
The steps must have flow control from
one process to another
The steps must terminate
The steps must lead to an output
Steps for
Developing
an
The input step
algorithm
The processing
step:Assignment
Decision
Iteration (Loop)
Arrays
The output step
Control structure
Control structures are instructions or
Control structures
Sequence
Selection ( if-then, if-then-else)
Iteration (while loop, repeat-until loop
and for loop)
Sequence
The sequence control structure is used when
you have instructions to be carried out in a
specific or particular order.
Example:Start
Read a, b
Sum = a + b
Print Sum
Stop
Selection
The selection control structure is used in
Example of
selection
Start
Read Score
If score>=75 then
Print Congrats you have passed
Else
Print "Sorry you have failed
Endif
Stop
Iteration
Iterations or loops are statements or
instructions that get repeated. There are two
types of Iterations:Bounded Repetition of a set of instructions a
fixed number of times. E.g. for-endfor
Unbounded Repetition of a set of
instructions a number of times until a
particular condition becomes false. E.g. Whileendwhile and repeat-until
Example of
iteration-Bounded
To accept 100 numbers and calculate their
sum.
Start
Sum = 0
For I = 1 to 100 do
Read x
sum = sum + x
Endfor
Stop
Example of
iteration-Unbounded
Find the sum of a set of numbers terminated by zero
Start
Declare sum, a
sum = 0
Read a
While a <> 0 do
Sum = sum + a
read a
Endwhile
Stop
Variables, Constants
and
literals
Each storage location in memory is
represented with a label called an
identifier
There are two kinds of identifiers:1. variables
2. Constants
Variables and
constants
A variable
identifies a memory location
literals
Literals are constants that are written
Data types
Data type indicates or tells the type of data a
variable can store
A variable can store the following data type:1. Integers( these include whole
numbers, positive or negative
numbers without decimal places
e.g. 230, -67, 0, -78
Data types
(contd)
2. Floating point
or Real (these are
Data type
Variable or
constant
Arithmetic
Operation Operators
Arithmetic operator
Addition
Subtraction
Multiplication
Division
Arithmetic
Operation Operators
Arithmetic operator
Finding the reminder in MOD eg 9 mod 2 = 1
a division operation
Integer division
DIV eg 11 div 4 =3
Relational
Operation Operators
Relational Operator
Greater than
>
Less than
<
<=
Equal
Not equal to
<>
Logical Operators
Operation
Operator
And
AND
Or
OR
Not
NOT
A and B A
A and B
TRUE
TRUE
TRUE
TRUE
FALSE FALSE
FALSE
FALSE TRUE
A OR B A
TRUE
TRUE
TRUE
FALSE
FALSE TRUE
FALSE FALSE
A OR B
FLOW CHART
Terminator indicates start or stop
Process indicates processing
Input/output indicates the input or output
of the problem
Decision used to make a decision between
two options ie yes or no
Flow control shows the flow of data
Connector used to connect part of a
flowchart that cannot fit on the page
Testing Algorithm
One good way of testing an algorithm is
14
-4
Top-down Design
Top-down design approach analyses the
Top-Down design
Question: The students from Grade10G
1. Research
2.Design the
Algorithm
3. Develop the
program
4. Integrate
Stepwise
refinement
Stepwise refinement is a more precise way to do topdown design. This breaks down a sub-problem into
smaller problems, then those smaller problems are
broken into smaller problems.
For example the Research the requirements of the
program can be broken down into smaller problems : One group can investigate the requirements of the
Sales Dept (Accounts Receivable).
Another group can investigate the requirements of
the Purchasing Dept (Accounts Payables).
Arrays
An array is a variable that can store a number
item2
item3
item4
item5
item6
apple
pear
mango
Declaring an array
Var <array name>: array [range] of <data
type>;
E.g. Var
fruits: array[16] of string;
Activity: Declare the following arrays
Variable name
salary
Studentname
Data type
real
string
Array size
20
10
Writing to an
array
Start
Reading from an
array
Start
Score: array[1..10] of integer
For i = 1 to 10 do
Write the student score is
Writeln (score [i])
Endfor
Stop
Traversing an
array
Start
Score: array[1..10]
For i = 1 to 10 do
Print please enter student score
read (score [i])
Endfor
For i = 1 to 10 do
score [i] =score [i]* 3
Writeln (score [i])
Endfor
Stop
Searching an array
linear search
For i = 1 to 10 do
if score [i] = 95 then
Writeln (Score found)
Else
Writeln (Score not found)
endif
Endfor
The End
Thank you!!!!!