Algrothim
Algrothim
Start
Read x and y
z=x + y
Print z
Stop
Check the no is positive or negative
Start
Read a number n
If n>0 then
“The number is positive”
Otherwise
“The number is negative”
End
Characteristics of a good algorithm
Input- An algorithm may take a zero or any number of inputs. The
number of inputs taken by an algorithm depends upon the nature of
the problem.
Output – An algorithm must produce one or more outputs. To put in
other word, every algorithm must give solution to the problem in the
form of output.
Termination or fitness – An algorithm must terminate after a finite
number of steps. It should end after a certain time. This should not
enter into to an infinite loop.
Generality – It indicates that the algorithm for a problem should be
general. It means the algorithm should work for all the values.
Effectiveness – It says that the operation must be simple and should be
done in a finite time to produce effective result.
Definiteness – It denotes that each instruction written in algorithm
must be clear, well-defined and precise.
Advantages of Good Algorithm
It is a program design tool.
It is programming language independent.
An algorithm gives solution of a problem.
A non technical person can easily understand it.
A single algorithm can be used to solve several similar
problems.
Disadvantages of Algorithm
Experience programmers think that writing an
algorithm is a waste of time and resource because they
can write a program directly.
Although, it gives logic of the problem, but is far away
from source code.(Pseudo code is very near to the
source code.)