# algorithm c8

```Problem solving
Problem solving
• Problem solving is a process of identifying a
problem and finding the best solution for it.
• Problem solving is a skill that can be developed
by following a well organized approach.
• Different problem solving technique are as
follows:
 Program
 Algorithm
 Flow chart
Program
• It is a set of instructions that tells a computer
what to do, computer works according to the
given instruction in the program.
• Computer programs are written in programming
languages.
• The programmer develops programs to instruct
the computer how to process data to convert into
information.
• Programmers use programming languages and
tools to write programs.
Algorithms and Pseudo Code
• An algorithm is a step by step procedure to
solve a problem.
• It is a better to write algorithm before writing
the actual computer program.
Properties of an Algorithm
Its properties are:
• The given problem should be broken into
simple and meaningful steps.
Algorithms and Pseudo Code
• The steps should be numbered sequentially.
• The steps should be descriptive and written in
simple English.
• Algorithms are written in a language which is
similar to simple English. This language is
known as Pseudo Language.
• Pseudo code is used to specify program logic
in an English like manner that is independent
of any particular programming language.
Algorithms and Pseudo Code
• This simplifies program development by
separating it into two main parts: logic design
and coding.
Logic Design: Logic of the program is designed.
We specify different steps required to solve the
problem and the sequence of these steps.
Coding: The algorithm is converted into a
program. The steps of algorithm are translated
into instructions of any programming language.
Algorithms and Pseudo Code
Example Algorithm accepts two numbers from
user calculates its sum and then displays the
result.
1. start
2. Input A,B
3. Total=A + B
4. Display total
5. Exist
Example 2
• The following algorithm inputs radius from the
user and calculates the area of circle.
1. Start
3. Area=3.14*r*r
4. Print area
5. End
Example 3
• Algorithm find the sum of first 20 numbers.
1. Start
2. Sum=0
3. Rapeat step 4 and 5 while(n<=20)
4. Sum=sum+n
5. N=n+1;
6. Print sum
7. End
Algorithms and Pseudo Code
Reduced Complexity: while writing the algorithm
we can focus on solving the problem instead of
concentrating on a particular language.
Increased Flexibility: Algorithm is written so that
the code may be written in any language that is
visual Basic, java ,C++ etc.
Ease to Understanding: You don't have to
understand a particular programming language to
understand an algorithm as it is written in English
like manner.
Flowchart
• It is a combination of two words: flow and chart.
• A chart consists of different symbols to display
• Flow represent the directions of processing that
takes place in the program.
• Flowchart is the graphical representation of an
algorithm that is used to show all the steps of an
algorithm in a sequence.
• An algorithm is first converted to a flowchart to
show its steps graphically then it is converted into
a program.
Uses of Flowchart
• To represent an algorithm in simple graphical
manner.
• To show the steps of an algorithm in an easy
way.
• To understand the flow of program.
• To improve the logic for solving a problem.
• Programs can be reviewed and debugged
easily.
Flowchart symbol
• Input/output
• The Data object, often referred to as the
I/O Shape shows the Inputs to and
Outputs from a process. This takes the
shape of a parallelogram.
• Start/End Symbol
• The terminator symbol marks the starting
or ending point of the system. It usually
contains the word "Start" or "End."
Decision / Conditional /Selection
• Decision object is represented as a Diamond.
Conditional typically contain a Yes/No
question or True/False test. This symbol is
unique in that it has two arrows coming out of
it, usually from the bottom point and right
point, one corresponding to Yes or True, and
one corresponding to No or False. The
arrows should always be labeled.
Flowchart symbol
• Process:
Flowchart Process object is used to illustrate a
process, action or an operation. These are
represented by rectangles; and the text in the
rectangle assignment statement.
• Subroutine / Predefined Process
This shape shows - 'Subroutine' or 'Predefined
Process'. Its called a subroutine if you use this
object in flowcharting a software program. This
allows you to write one subroutine and call it as
often as you like from anywhere in the code.
Flowchart Symbols
Flow lines: Arrow symbols are used to represent
the direction of flow in the flowchart they are of
four types: Up, Down, Left and right.
Connecter: Circle symbol is used to combine
different flow lines it is used when two or more
flow symbols come from different direction and
moves to one direction.
Basic Flowchart Symbols
Flow chart represent the steps for
start
Input
a,b
Sum=a+b
Display
sum
End
Difference Between Pseudo Code and
flow chart
Flowchart
Algorithm/Pseudo Code
Flow chart Contains standard symbol to
represent different computer operations
There is no standard for writing pseudo
code
Flow chart is less frequently used as it
takes more time to design
Pseudo code is more frequently used as it
takes less time
It is difficult to modify
It is easier to modify
It is a graphical representation of solution
It is not graphical representation of
solution. It is a step by step procedure to
solve a problem.
Program Development Process
• A program has to go through the following
stages to develop a computer program:
• Defining And Analyzing The Problem
• Designing The Algorithm
• Coding Or Writing The Program
• Testing Program
• Final Documentation
Defining And Analyzing The Problem
• In this step a programmer studies the problem.
he decided the best way to solve this problem.
Studying a problem is necessary because it helps
a programmer to decide about the following
things:
 The fact and figure which necessary for
developing the program.
 The way in which program will be designed
 The language in which the program will be most
suitable
 What is desired output etc
Designing The Algorithm
• An algorithm is a sequence of steps that must
be carried out before a programmer starts
preparing his program. The programmer
designs an algorithm to help visualize possible
alternatives in a program.
Coding or writing the Program
• The process of writing a program is a very
important step in program development. In
this step algorithm is converted into program.
• The program consists of different steps given
in algorithm. A large number of programming
language are available to write programs. The
programmer selects the programming
language according to the nature of problem.
Testing Program
• A program must be tested in the process of
program development. This step verifies the
accuracy of a program. the program is tested
by executing it again and again. Different
values are given as input and output is
checked. The error must be detected and
corrected if the output is not correct. It ensure
that program gives desired results and
problem is solved correctly.
Final Documentation
• When the program is finalized its
documentation
is
prepared.
Final
documentation is provided to the user. It
guides the user how to use the program in
most efficient way. Another purpose of
documentation is to allow some other
programmer to modify the code if necessary.
Documentation should be done in each step
during development of a program.
```