Unit 1 Probelm Solving Fundamentals
Unit 1 Probelm Solving Fundamentals
In fact, the task of problem solving is not that of the computer. It is the
programmer who has to write down the solution to the problem in
terms of simple operations which the computer can understand and
execute
Step by Step Procedure
Understanding the problem : Here we try to understand the problem to be
solved in totally. Before with the next stage or step, we should be absolutely sure
about the objectives of the given problem.
Coding and implementation: The last stage of the problem solving is the
conversion of the detailed sequence of operations in to a language that the
computer can understand. Here each step is converted to its equivalent
instruction or instructions in the computer language that has been chosen for
the implantation.
Problem Definition
Develop an algorithm.
Example : (data1+data2)/2
Problem Definition – Develop an
Algorithm
An algorithm is the sequence of operations to be
performed.
Algorithm :
STEP 1 : START
STEP 2 : Declare Three variables a, b, avg
STEP 3 : Define Values of a & b
STEP 4 : ADD Values of a & b then compute the average, divide the sum by two
STEP 5 : Store Output of Step 4 to avg
STEP 6 : Print avg
STEP 7 : STOP
The compiler will convert the program code to the machine language
which the computer can understand.
Problem Definition – Test the Program
When the compiler find the bugs, it prevents compiling the code from
programming language to machine language.
Input to numbers
A, B C =A+ B C
Input Processing Output
Characteristics of a Programs
Portability:- Portability refers to an application to run on a different platform, which or
without minimum changes.
Efficiency:- Live program at required certain processing time and memory to process the
instruction and data a program should be let out in such a manner, that it utilized the least
amount of memory and processing time.
Characteristics of a Programs
Flexibility:-A program is flexible enough to handle most of the changes without having the rewrite
the entire program, most of the program is dependent on a certain period and their required
modification from time to time.
Generality:-Apart from the flexibility of the program should also be general. By Generality, we
mean that, if a program is developed for a particular task, then it should also be used for all similar
tasks of the same domain.
The programmer should have wide knowledge about the problem and the way to
solve it.
Problem Analysis.
Program coding
Documentation.
Program Development Cycle – Problem
Analysis
Define the problem by identifying the input and output of it.
Algorithm can be of
Flow Chart
Pseudo Code
Program Design Language (PDL) : It has no specific standard rules for defining the PDL
statements. PDL is independent of any programming language. It is also called as Pseudo
Code.
Program Development Cycle : Program
Coding
Code the algorithm in the selected programming language
It may be possible to solve problem in more than one ways, resulting in more than
one algorithm.
The choice of various algorithms depends on the factors like reliability, accuracy
and easy to modify.
Algorithm
The algorithm which will need the least time when executed is
considered the best.
Steps Involved in Algorithm Development
Processing Finiteness: If we go through the algorithm, then for all cases, the
algorithm should terminate after a finite number of steps.
Step 3 : Find the larger number between A and B and Store it in MAX_AB
Step 4 : Find the larger number between MAX_AB and C and Store it in MAX.
Step 6 : Stop
Flowchart
Flowchart is a diagrammatic representation of an algorithm that illustrates
the sequence of operations to be performed to get a solution.
The boxes represent operations and the arrows represent the sequence in
which the operations are implemented.
Symbol
Symbol Description
Name
Flow Lines are used to connect symbols. These lines
Flow Line indicate the sequence of steps and the direction of flow
of control.
Symbol
Symbol Description
Name
Process symbol used for representing arithmetic and
data movement instructions. It can represent single
Processing
step (add two cups of flour) or an entire sub process
(make bread) within a larger process.
Decision symbol denotes (or branch) to be made. The
program should continue along one of the two routes
(if/else).
Decision
This symbol has one entry and two exit paths. The path
chosen depends on whether the answer to a question is
yes or no.
Flowchart - Symbols
Symbol
Symbol Description
Name
Symbol
Symbol Description
Name
Symbol
Symbol Description
Name
Communication
Communication link symbol is used to represent data
Link
In drawing proper flowchart, all necessary requirements should be listed in logical order.
Only one flow line should come out from a process symbol.
Only one flow line should enter a decision symbol. However, two or three flow lines (one for each
possible answer) may leave the decision symbol.
In case of complex flowcharts, connector symbols are used to reduce the number of flow lines.
Benefits of Flowcharts
A flowchart helps to clarify how things are currently working and how they could be
improved. The reasons for using flowcharts as a problem solving tool are given below.
Makes Logic Clear
Communication
Effective Analysis
Useful in Coding
Proper Testing and Debugging
Appropriate Documentation
Limitations of Flowcharts
Flowchart can be used for designing the basic concept of the program in
pictorial form but cannot be used for programming purposes. Some of the
limitations of the flowchart are given as follows.
Complex
Costly
Difficult to Modify
No Update.
Control Structure of Flowcharts - Sequence
Start
Example of Flowchart
(Product of any two Numbers)
Start
Read A, B
C =A* B
Print C
Stop
Control Structure of Flowcharts - Selection
Is No
Condition is
True
Yes
Start
Read A, B, C
Example of Is A > B
No
Flowchart Yes
MAX = A MAX = B
(Finds the
Maximum of No
Is MAX > C
Three Numbers) Yes
Print MAX Print C
Stop
Control Structure of Flowcharts - Iteration
No Is
Condition is
True
Yes
Start
SUM = 0 & I = 0
Example of I=I+1
Flowchart SUM = SUM + I
(Find the
No
Sum of First Is I >=100
Stop
Thank You