Week 3 - Problem Solving and Algorithm
Week 3 - Problem Solving and Algorithm
Week 3
Problem Solving and Algorithms
Topics
Describe pseudocode,
At the end of this
flowchart, and algorithm
lecture, YOU will be Define algorithm
to develop, test and
able to:-
debug a program
• Computers everywhere
Ovens, washing machines and toys. Banks and
Hospitals, Transport Reservations, Signaling
Aircraft and industrial plant controllers, Missiles
and satellites, and many more.
What is Problem ?
01 02 03 04 05 06
Define the Determine the Develop Select a Implement the Evaluate the
Problem Root Cause(s) Alternative Solution Solution Outcome
of the Problem Solutions
Purpose: How
To describe in detail a solution to • Study and understand the problem
a problem and information • Identify
needed in solving the problem. • The needed input.
• The required output.
• The needed process.
• For example: scientific
formula or hypothesis.
Problem 1
Write a program that will calculate and
display the average of 3 numbers
Problem 2
Write a program that will convert length
in kilometer to meter and centimeter
• Ask questions!
– What do I know about the problem?
– What is the information that I have to process in order to find
the solution?
– What does the solution look like?
– What sort of special cases exist?
– How will I recognize that I have found the solution?
Pseudocode
Often use one of three Flowcharts
tools: Nassi-Schneiderman diagrams –
will not be covered in this module
Creating algorithms is all about thinking logically and so to think computationally is to think in a
structured, organized and logical manner.
Algorithms are vital to programming. Without one, coding a solution is almost impossible…but with
one, coding becomes an easy job (if you know your programming syntax that is!)
Your Facebook news feed is derived from your friends’ status updates
and other activity, but it only shows that activity which the algorithm
thinks you’ll be most interested in seeing.
The recommendations you get from Amazon, Netflix and eBay are
algorithmically generated, based in part on what other people are
interested in.
There will be a sequence of steps pupils follow for many activities, such as getting ready for
lunch or going to PE.
So, we use Flowcharts and pseudocode to write algorithms so that they are concise,
accurate and easy to understand so that a programmer of any language could understand
the steps required to solve a task
Problem 1
Write a program that will calculate and
display the average of 3 numbers
ALGORITHM
Problem 2
Write a program that will convert length
in kilometer to meter and centimeter
ALGORITHM
No standard pseudocode.
Pseudo-code has keywords such as IF, ELSE and FOR and so mimics a programming language and therefore the logic is easy to
follow and easy to turn into code.
Although there are no STRICT STANDARDS for pseudocode there are only really a few keywords that you need.
We do not have to follow any strict syntax like computer programming language
Pseudo code commonly borrows its syntax from popular programming languages like C, Fortran, Pascal, Java, Python etc.
At times, your program will most certainly ask the user for inputs and output values too.
Inputs and Outputs (like “Name?” or “…display age”) are indicated using the following words.
Usually, a programmer will choose one and stick with it throughout their algorithm.
READ
OBTAIN
INPUTS: GET
INPUT
PRINT
DISPLAY
OUTPUTS: SHOW
OUTPUT
Simple processes will often use the key words shown below (like “CALCULATE X*2” or “INCREMENT X by 1)”
You don’t have to always use these words, for example the logic statements such as “Add 1 to x” or “append x to List”
are fine too.
Example:
Compute Calculate Determine Increment; ++ or += Decrement; -- or -=
• At times, your program will be programmed to make a decision based on certain conditions.
• Decisions (like “IF X = 3, THEN …”) are shown using, the following key words.
• IF
• THEN
• ELSE
• ELSE-IF
• ENDIF
• Programs will often loop in places while certain conditions occur (infinitely) or for a set number of times (finitely).
• Loops use the following key words:
• FOR
• WHILE / ENDWHILE
• REPEAT / UNTIL
Problem 1
Write a program that will calculate and
display the average of 3 numbers
Pseudo code
Problem 2
Write a program that will convert length
in kilometer to meter and centimeter
Pseudo code
• Example 3:
– A central heating system will try to keep the temperature
between 2 values (19 and 21)
– If the temperature falls below 19 It will turn the heating system
on
– If the temperature rises above 21 it will switch the heating
system off.
Flowchart is a pictorial way to Visual representation of the logic Limited range of symbols to Arrows to show the order of
express algorithm or process. of a program describe processes instructions
• Process Symbols
– Most of the time a flow chart will demonstrate the sequence of
instructions to be carried out.
– Simple processes (like “Add 1 to x” or “append x to List”) are
shown using a standard rectangle.
• Decision Symbols
– At times your program will be programmed to make a decision
based on certain conditions.
– Decisions (like “IF X = 3” or “While Y > 3”) are shown using a
diamond.
• Flow Symbols
– Show direction of flow.
Problem 1
Flowchart
Problem 2
Flowchart
Definition
Using a set of data to discover Testing Process
errors and to ensure accuracy of
the program. Diagram indicates the
process of testing.
Output
Input (functioning
Executing
sample of well or error
Program
data set discovered)
TESTING
Testing 1:
From the output,
Input: 4, 5, 8 has the program
produced the
expected result?
Testing 2:
Input: 7, 8, 6
DEBUGGING
Definition
Program documentation
Definition:
Note: that you don’t
A written or graphical perform documentation
report of the steps taken all at the end of the
during the development of programming life cycle,
a program. instead what usually
happens is that you
write documentation
Purpose along the way and at
It will be useful in the the last step, double
future, in case of check to make sure
modification or that all documentation
maintenance. have been completed
DEFINITION
The process of changing a system after it has been applied to maintain its
ability.
Adjustment
Testing
Adding needs to new system.
Test the ability of the system.
Updating Replacement
Update the database. Replace the old system to new
system.
Content of Documentation:
Description of the program
Test results
Specification of program requirement
User’s manual book
Program design such as pseudo code
and flowchart Program capabilities and limitation
Thank You
Variables and Boolean