2-Problem solving techniques
2-Problem solving techniques
SOLVING
TECHNIQUES
INSTRUCTOR: JAVERIA NAZ
What is Problem
Solving?
A process of identifying a problem and finding its best
solution is known as problem solving.
In this process the descriptions of problem are
transformed into its solution.
The problem can be solved in different ways.
However, the most suitable way should be selected to
solve a problem.
Phases of Program
Development
The general phases of program development are:
1. Planning
2. Analysis
3. Design
4. Coding
5. Testing
6. Implementation
7. Maintenance
Problem Solving
Techniques
A typical programming task can be divided into two
phases:
1. Problem solving phase
produce an ordered sequence of steps that
describe solution of problem
this sequence of steps is called an algorithm
2. Implementation phase
implement the program in some programming
language
Steps in Problem Solving
Example 1
Write an algorithm to determine a student’s final grade and
indicate whether it is passing or failing. The final grade is
calculated as the average of four marks.
Pseudocode & Algorithm
Pseudocode:
Input a set of 4 marks
Calculate their average by summing and dividing by 4
if average is below 50
Print “FAIL”
else
Print “PASS”
Pseudocode & Algorithm
Detailed Algorithm
Step 1: Start
Step 2: Input M1,M2,M3,M4
Step 3: GRADE = (M1+M2+M3+M4)/4
Step 4: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
end if
Step 5: Stop
The Flowchart
(Dictionary) A schematic representation of a sequence of
operations, as in a manufacturing process or computer
program.
(Technical) A graphical representation of the sequence of
operations in an information system or program.
Information system flowcharts show how data flows from
source documents through the computer to final
distribution to users. Program flowcharts show the
sequence of instructions in a single program or subroutine.
Different symbols are used to draw each type of flowchart.
The Flowchart
A Flowchart
◦ shows logic of an algorithm
◦ emphasizes individual steps and their interconnections
◦ e.g. control flow from one action to the next
Flowchart Symbols
Name Symbol Use in Flowchart
Step 1: Start
Input
M1,M2,M3,M4 Step 2: Input M1,M2,M3,M4
Step 3: GRADE =(M1+M2+M3+M4)/4
GRADE(M1+M2+M3+M4)/4
Step 4: if (GRADE <50) then
Write “FAIL”
N IS Y
GRADE<5 else
0
Write “PASS”
WRITE WRITE
PASS FAIL end if
Step 5: Stop
STOP
Example 2
Write an algorithm and draw a flowchart to convert the
length in feet to centimeter.
Pseudocode:
Input the length in feet (Lft)
Calculate the length in cm (Lcm) by multiplying Lft with 30
Print length in cm (Lcm)
Example 2
Flowchart
Algorithm
START
Step 1: Start
Input
Step 2: Input Lft Lft
STOP
Example 3
Write an algorithm and draw a flowchart that will read the
two sides of a rectangle and calculate its area.
Pseudocode
Input the width (W) and Length (L) of a rectangle
Calculate the area (A) by multiplying L with W
Print A
Example 3
Algorithm
START
Step 1: Start
Input
Step 2: Input W,L W, L
Step 3: AL x W
Step 4: WRITE A A LxW
Step 5: Stop
WRITE
A
STOP
Example 4
Write an algorithm that reads two values, determines the largest value
and prints the largest value with an identifying message.
ALGORITHM
Step 1: Start
Step 2: Input VALUE1, VALUE2
Step 3: if (VALUE1 > VALUE2) then
MAX VALUE1
else
MAX VALUE2
endif
Step 4: Write “The largest value is”, MAX
Step 5: Stop
Example 4 START
Input
VALUE1,VALUE2
Y is N
VALUE1>VALUE2
WRITE
MAX
STOP
Advantages of
Flowchart
1. With the help of flowchart logic of program can
be described easily and more effectively.
2. Flowchart are a part of design phase, by using
flowchart maintenance of operational program
become more easy.
3. A flowchart help programmer in writing a
program.
4. A flowchart also help in debugging the program
Limitations of
Flowchart
Flowcharts also have some limitations. These
limitations are as follows:
1. It is difficult to draw a flowchart for complex
problem.
2. The flowchart has to be redrawn or redesigned if
any change in the problem /requirements is
required.
Questions:
1. Write pseudocode, algorithm and also draw flowchart for
the following: