9/19/2013
Learning Outcomes
Types of problem.
Recognize 6 steps in problem solving.
Recognize 7 steps in program development process.
Pseudocode and Algorithm
Difficulties with problem solving with computer
Types of problem
Algorithmic solutions
Can be solved with a series of actions (algorithms)
Heuristic solutions (rule of thumb)
Based on knowledge & experience
Requires a process of trial and error
Types of problem (cont)
6-steps can be used for both problems
But step 6 (for heuristic solutions)
Correctness and appropriateness far less certain
May need to iterate (repeat) many times
Same solution may not work all the time
Log on to an e-mail account
Withdraw cash from ATM machine
Add Salt to food (during cooking)
Buying the best stock
Problem solving with computers
Computers built for dealing with algorithmic solutions
Write instruction step by step
Heuristic solutions requires (Artificial) intelligence
The program can make decision like human when for
each situation base on previous solution
Need to transform into algorithmic format
Most problems require a combination of the two kinds
of solutions
Driving a vehicle
Fix a malfunction computer
9/19/2013
Problem Solving in Everyday Life
Problem-solving process (6 steps)
Problem Solving in Everyday Life
Example : You are doing assignment at home, and you
Identify the problem
What to do?
Understand the problem
Knowledge base required
Identify alternatives
Other acceptable methods
are hungry
Identify problem : you are hungry
Understand the problem : you need food
Identify Alternatives :
Select the best way to solve the problem
List the instructions
All steps required
Evaluate the solution
Check to see if result is correct
Problem Solving in Everyday Life
Example (continued)
Select the best way
Problem Solving in Everyday Life
Example (continued)
List out the instruction
Method 1 : you arent kid anymore
Method 2 : might be a good idea
Method 3 : you might not have time since you are
doing assignment.
Method 4 : might be expensive
Method 5 : you might not have time since you are
doing assignment.
Programming can be defined as the development of a
solution to an identified problem, and the setting up
of a related series of instructions that will produce
the desired results
Define the Problem
To help with initial analysis, the problem should be
divided into three separate components:
the inputs
the outputs
the processing steps to produce the required outputs
Go out from the room
Go to kitchen
Search the table, cabinet, refrigerator for food
Consume the food
evaluate the solution
After some consideration, let say you choose method 2
7 Steps of Program Development Process
1.) look for mum
2.) go to kitchen and look for some food
3.) go to kitchen and prepare food yourself
4.) make a food delivery order
5.) go out to have a meal in restaurant / hawker center
Is the solution help to solve the problem?
Is the solution solve the problem efficiently?
Should we follow the same solution next time?
7 Steps of Program Development Process
1.
Define the problem
2. Outline the solution
3. Develop an algorithm (based on the outline)
4. Test the algorithm (for correctness)
5. Code the algorithm (into a specific programming language)
6. Run the program (on the computer)
7. Document & Maintain the program
9/19/2013
1 Define the Problem
To help with initial analysis, the problem should be
divided into three separate components:
the inputs
the outputs
the processing steps to produce the required outputs
Use IPO chart (Input Process Output chart)
1 Define the Problem
Example:
Shop A is offering a 20% discount for all products.
Calculate the payment for the customers.
Input
Output
Process
2 Outline the Solution
This initial outline is usually a rough draft of the
solution and may include:
The major processing steps involved
The major subtasks (if any)
The user interface (if any)
The major control structures (e.g. repetition loops)
Discount rate, original price of the products
payment
Calculate payment
2 Outline the Solution
Example (step by step to solve the problem) :
Get the price of product purchase by the customer
Get the discount rate
Calculate the discount amount
Calculate the payment after discount
Display the payment amount to the customer
The major variables and record structures
The mainline logic
3 Develop the Outline into an Algorithm
The solution outline developed in Step 2 is expanded
into an algorithm: a set of precise steps that describe
exactly the tasks to be performed and the order in
which they are to be carried out
Develop flow chart and pseudocode from IPO chart
4 Test the Algorithm for Correctness
This step is one of the most important in the development
of a program, and yet it is the step most often forgotten
The main purpose of desk checking (test the algorithm) is
to identify major logic errors early, so that they may be
easily corrected
Early error identification is better because will save time
and cost
9/19/2013
5 Code the Algorithm into a Specific
Programming Language
Only after all design considerations have been met
should you actually start to code the program into your
chosen programming language (e.g c++, c , Java)
7 Document and Maintain the Program
Program documentation should not be listed as the
last step in the program development process, as it is
really an ongoing task from the initial definition of the
problem to the final test result
Documentation involves both external documentation
and internal documentation that may have been coded
in the program
What Is an Algorithm?
An algorithm is like a recipe: it lists the steps involved
in accomplishing a task
It can be defined in programming terms as a set of
detailed, unambiguous and ordered instructions
developed to describe the process necessary to
produce the desired output from a given input
6 Run the Program on the Computer
This step uses a program compiler and programmer-
designed test data to machine test the code for
syntax errors and logic errors
Algorithms and Pseudocode
A program must be systematically and properly
designed before coding begins
This design process results in the construction of an
algorithm
Types of algorithm
From algorithm, we also can have:
Pseudocode (more English-like)
Flowcharts
Nassi-Schneiderman diagrams
As all above are all popular ways of representing
algorithms
9/19/2013
Difficulties with problem solving
Why difficult to solve problem
Most people do not complete adequately the problemsolving process
Problem-solving process requires time and practice
Problem with writing the instruction
E.g. List 5 numbers and pick the largest one.
(Can you explain/list all the steps required?)
Computer (a tool) can perform only task that user can explain
step by step
All steps must be in proper order
Summary
The steps in program development were introduced
and briefly described below:
1. Define the problem
2. Outline the solution
3. Develop the outline into an algorithm
4. Test the algorithm for correctness
5. Code the algorithm into a specific programming
language
6. Run the program on the computer
7. Document and maintain the program