Professional Documents
Culture Documents
FALLSEM2015-16 CP1416 14-Jul-2015 RM01 Session-3
FALLSEM2015-16 CP1416 14-Jul-2015 RM01 Session-3
Step 2
Understand the problem
- Must
understand what is involved in the
problem before you can continue
toward the solution
If you are setting up a solution for a
person, then you must know what that
person knows.
For example, to tell someone how to
find a restaurant in your city if he has a
limited knowledge of the city you can
only use the information known to him
Step 2
Knowing the knowledge base is very
important since you cannot use any
instructions outside this base
Must also know knowledge base of the
problem solver
Cannot solve a problem if the problem
solver do not know the subject
For example, to solve a problem
involving calculus, you must know
calculus; to solve a problem involving
accounting, you must know accounting.
Step 2
In the case of computer problems,
understanding the problem involves
identifying
Input available for the problem
Output to determined
Process in involved in achieving the output
from the given input
Step 3
Step 3
But sea seems to be infeasible solution
for this problem
Step 4
Select the best way to solve the
problem from the list of alternative
solutions.
Need to identify and evaluate pros and
cons of each possible solution before
selecting best one.
In order to do this, you need to select
criteria for the evaluation.
These criteria will serve as the
guidelines for evaluating each solution.
Step 5
Step 6
Evaluate the solution.
To evaluate or test a solution means to check
its result to see if it is correct, and to see if it
satisfies the needs of the person(s) with the
problem.
When a person needs a piece of furniture to
sleep on, buying her a cot may be a correct
solution, but it may not be very satisfactory.
If
the
result
is
either
incorrect
or
unsatisfactory, then the problem solver must
review the list of instructions to see that they
are correct or start the process all over again.
3. Identify alternatives.
Watch television
Invite friends over
Play video games
Go to the movies
Play miniature golf
Go to the amusement park
Go to a friends party.
Types of Problems
Some
problems
have
straightforward
solution and others do not
Some problems, such as balancing a
checkbook or baking a cake, can be solved
with a series of actions
These are algorithmic solutions.
Once the alternatives have been eliminated,
for example, and once one has chosen the
best among several methods of balancing
the checkbook, the solution can be reached
by completing the actions in steps.
These steps are called the algorithm.
Types of Problems
Solutions of other problems, such as how
to buy the best stock or whether to expand
the company, are not so straightforward.
These solutions require reasoning built on
knowledge and experience, and a process
of trial and error.
Solutions that cannot be reached through
a direct set of steps are called heuristic
solutions.
Problem solver can use the six steps for
both algorithmic and heuristic solutions.
Types of Problems
However, in step 6, evaluating the solution,
the correctness and appropriateness of
heuristic solutions are far less certain.
Its easy to tell if your completed checkbook
balance is correct and satisfactory, but its
hard to tell if you have bought the best
stock.
With heuristic solutions, the problem solver
will often need to follow the six steps more
than once, carefully evaluating each possible
solution before deciding which is best.
Process of Computational
Problem Solving
Computational problem solving does not simply
involve the act of computer programming.
It is a process, with programming being only one
of the steps.
Before a program is written, a design for the
program must be developed.
And before a design can be developed, the
problem to be solved must be well understood.
Once written, the program must be thoroughly
tested
Phase 2:
Programming phase.
Stuff to look at
Problem Solving Basics and Computer
Programming, by By Ronald A. Pasko
http://www.cs.iit.edu/~cs100/ProblemSolving.
pdf
Problem Description
Given the 3 dimensions of a box (length,
width, and height), multiply them together to
determine the volume
description in 4 steps
Identify all of the nouns in the sentence
Process
Identify all of the verbs in the sentence
PRE-PROGRAMMING PHASE
Analyzing the problem.
Developing the Hierarchy Input
Process Output (HIPO) chart or
Interactivity Chart (IC).
Developing the Input-ProcessOutput (IPO) Chart.
Drawing the Program flowcharts.
Writing the algorithms.
Processing
Salary =
Hours work *
payrate
Output
Salary
Solution
Alternatives
1. Define the
hours worked
and pay rate
as constants.
2. Define the
hours worked
and pay rate
as input
values.
PAC
to
Convert
Miles
to
Kms
Convert the distance in miles to
kilometers where 1.609 kilometers per
mile.
Data
Distance in
miles
Processing
Output
Solution
Alternatives
Kilometers =
1.609 x miles
Distance in
kilometers
1. Define the
miles as
constants.
2. Define the
miles as
input values.
Logic
Definition : A method of human thought
that involves thinking in a linear, step by
step manner about how a problem can be
solved
Logic is a language for reasoning. It is a
collection of rules we use when doing reasoning.
Example
John's mum has four children.
The first child is called April.
The second May.
The third June.
What is the name of the fourth child?
ut
Print
Prime
or Not
Prime
Problem Description
Write a problem analysis chart (PAC)
that asks a user to enter the distance
of a trip in miles, the miles per gallon
estimate for the users car, and the
average cost of a gallon of gas.
Calculate and display the number of
gallons of gas needed and the
estimated cost of the trip.
Processing
Output
distance,
miles per
gallon,
cost per
gallon
gas needed =
distance / miles
per gallon.
Display gas
needed
estimated cost =
cost per gallon x
gas needed
Display
estimated cost
HIPO
Interaction will form a hierarchy,
called Hierarchy Input Process Output
Chart (HIPO) or Interactivity Chart
(IC).
Main
Module
Module 1
Module 4
Module 2
Module 3
Module 5
Module 6
READ
CALCULA
TE
Calculate
Gross Pay
Accumulate
Hourly
Worked
Determine
Pay rate
Calculate
Net Pay
Calculate
Deduction
s
Write
Cheque
Processing
- Enter distance
- Enter miles per gallon
- Calculate total gas
needed
- Enter cost gas per gallon
- Calculate estimated cost
- Display total gas and
estimated cost
- End
Output
-Total gas
needed
- Estimated
cost
Calculate gas
Estimation
Input Data
Processing
Output
Number, N
Solution Alternatives
1. Divide N by numbers from 2 to N and if for
all the division operations, the reminder is non
zero, the number is prime otherwise it is not
prime
2. Same as 1 but divide the N from 2 to N/2
3. Same as Logic 1 but divide N from 2 to
square root of N
Flow Chart
Implementation
n = int(input())
x = n // 2
# For some y > 1
counter = 2
while counter <= x:
if n % counter == 0:
#
Remainder
print(The given number
is Composite)
break # Skip else
counter += 1
else:
# Normal exit
print(The given number is prime')
Debugging
Correct Syntactical / logical errors
Testing
Generate Test cases with boundary
conditions:
A prime number Eg: 19
A composite number Eg: 24
Boundary Conditions: 0,1, 2.3
For 1 Print the number is neither prime nor
composite
For 0 Invalid input
For 2.3 Invalid input