Problem Solving Techniques
Problem Solving Techniques
The problem solving process starts with the problem specifications and
ends with a Correct program.
PROBLEM SOLVING TECHNIQUES
• Problem solving technique is a set of techniques that helps in providing logic for
solving a problem.
• Problem Solving Techniques:
1. Algorithms.
2. Flowcharts.
3. Pseudo codes.
4. programs
ALGORITHM
It is defined as a sequence of instructions that describe a method for
solving a problem. In other words it is a step by step procedure for
solving a problem.
Properties of Algorithms
• Should be written in simple English
Step 1: Start
Step 3: Stop
BUILDING BLOCKS OF ALGORITHMS :
1. sequence
2. selection
3. iteration
Sequence:
All the instructions are executed one after another is called sequence execution.
Example:
Step 4: Display c
Step 5: Stop
Selection:
A selection statement causes the program control to be transferred to a
specific part of the program based upon the condition.
If the conditional test is true, one part of the program will be executed,
otherwise it will execute the other part of the program.
Example
Write an algorithm to check whether he is eligible to vote?
Step 1: Start
Step 6: Stop
Iteration:
In some programs, certain set of statements are executed again and
again based upon conditional test. i.e. executed more than one time.
This type of execution is called looping or iteration.
Example
Write an algorithm to print all natural numbers up to n
Step 1: Start
Step 6: go to step 4
Step 7: Stop
Pseudocode:
Python pseudocode is more like an algorithmic representation of the
code involved.
This means when a code is expected to be formulated it cannot be
directly drafted.
The code will need to be first generated into a Python pseudocode and
then it needs to be formulated into an actual code.
Basic rules before writing pseudocode:
• Write only one statement per line.
• Write what you mean, not how to program it
• Give proper indentation to show hierarchy and make code
understandable.
• Make the program as simple as possible.
WRITE A PSEUDOCODE TO FIND THE LARGEST OF TWO NUMBERS.
BEGIN
NUMERIC nNum1,nNum2
DISPLAY "ENTER THE FIRST NUMBER : "
INPUT nNum1
END
WRITE A PSEUDOCODE TO FIND THE SUM OF TWO NUMBERS.
begin
numeric nNum1,nNum2,nSum
display "ENTER THE FIRST NUMBER : "
accept nNum1
display "ENTER THE SECOND NUMBER : "
accept nNum2
compute nSum=nNum1+nNum2
display "SUM OF THESE NUMBER : " nSum
end
WRITE A PSEUDOCODE TO FIND THE AREA OF
RECTANGLE.
begin
numeric nLen,nBrd,nAre
display "ENTER THE LENGTH OF RECTANGLE : "
accept nLen
display "ENTER THE BREADTH OF RECTANGLE : "
accept nBrd
nAre=nLen*nBrd
display "AREA OF RECTANGLE : " nAre
end
Flowcharts:
• Flowcharts graphically represent the flow of a program. There are four
basic shapes used in a flow chart. Each shape has a specific use:
• oval: start / end
• parallelogram: input / output
• rectangle: calculations
• diamond: selection structures
Arrows connect the basic shapes in a flowchart. The shapes and arrows of a
flowchart describe the flow of a program from start to end. Flowcharts typically
flow from the top to the bottom or flow from the left to the right.
A flowchart that describes this simple program is shown.
# start
num = input("Enter a number: ")
num = float(num)
num_plus_2 = num + 2
print(num_plus_2)
# end
To check number is greater than zero :
# start
num = input("Enter a number: ")
num = float(num)
if num>0:
print("Greater than 0")
# end
Program :
If the number is greater than zero, then the program prints "Greater
than 0". If the number is less than zero, then the program prints "Less
than 0". Then the program prints "Done" and the program ends.
The Python code that corresponds to this flow chart is:
# start
num = input('Enter a number: ')
num = float(num)
if num>0:
print('num greater than zero')
if num<0:
print('num less than zero')
print('Done')
# end