6. Title text
addition
Ø An algorithm can be defined as a finite set of steps, which has to be followed while carrying
out a particular problem.
Ø An algorithm is a distinct computational procedure that takes input as a set of values and
results in the output as a set of values by solving the problem. If an algorithm is correct, it
gets the correct output and terminates correctly, for each of the input instance .
Ø It can be written using a natural language such as English, Computer language or a
hardware language.
Ø Created independent of programming languages
Ø Algorithm is a finite set of instructions that if followed, accomplishes a particular task.It is a
step by step procedure for performing some task in a finite amount of time.
Definition :
A finite set of instruction that specifies a sequence of operation to be carried out in
order to solve a specific problem or class of problems is called an Algorithm.
7. Title text
addition
v Input : An algorithm has zero or more input quantities that are given initially before an
algorithm begins.
v Output : At least one output quantity is produced
v Definiteness: Each instruction is clear and unambiguous .It should be precisely defined.
v Finiteness : Problem must be solved in a finite number of steps and produce appropriate
results. The range of inputs for which the algorithm works perfectly should be specified.
v Effectiveness : Every instruction must be very basic so that it can be carried out, in
principle, be a person using only pencil and paper.
v Unambiguous : Algorithm should be clear and unambiguous. Each of its steps (or phases),
and their inputs/outputs should be clear and must lead to only one meaning.
8. Title text
addition
Ø Feasible: It must be feasible enough to produce each instruction.
Ø Flexibility: It must be flexible enough to carry out desired changes with no efforts.
Ø Efficient: The term efficiency is measured in terms of time and space required by an
algorithm to implement. Thus, an algorithm must ensure that it takes little time and
less memory space meeting the acceptable limit of development time.
Ø Independent: An algorithm must be language independent, which means that it
should mainly focus on the input and the procedure required to derive the output
instead of depending upon the language.
9. Title text
addition
Advantages of an Algorithm
v Effective Communication: Since it is written in a natural language like English, it
becomes easy to understand the step-by-step delineation of a solution to any
particular problem.
v Easy Debugging: A well-designed algorithm facilitates easy debugging to detect
the logical errors that occurred inside the program.
v Easy and Efficient Coding: An algorithm is nothing but a blueprint of a program
that helps develop a program.
v Independent of Programming Language: Since it is a language-independent, it
can be easily coded by incorporating any high-level language.
10. Title text
addition
Disadvantages of an Algorithm
Ø Developing algorithms for complex problems would be time-consuming and
difficult to understand.
Ø It is a challenging task to understand complex logic through algorithm
11. Title text
addition
Ø To understand the basic idea of the problem.
Ø To find an approach to solve the problem.
Ø To improve the efficiency of existing techniques.
Ø To understand the basic principles of designing the algorithms.
12. Title text
addition
1. How to devise algorithms?
Ø Different design strategies like backtracking , divide and conquer etc. are used to
devise new algorithms.
2. How to express algorithms?
Ø The algorithm must be expressed using a programming language so that the
computer understands the problem.
Ø Every procedure should be carefully specified with its input and output variables.
Proper documentation should also be done.
13. Title text
addition
3. How to validate algorithms?
Ø It is necessary to check if correct answer is obtained for all possible legal inputs.
The algorithm validation assures the algorithm to work correctly independent of the
programming language. Program proving or program verification follows .
Ø A proof of correctness requires that the solution be stated in two forms usually
annotated as a set of assertions about the input and output variables and as
predicate calculus. A proof shows that these two forms are equivalent for any legal
input.
4. How to analyze algorithms?
Ø Analysis of algorithms or performance analysis refers to the task of determining
how much computing time and storage an algorithm requires
14. Title text
addition
5. How to test a program?
Ø Testing is to ensure that the program works accurately and efficiently before the live
operation starts. There are two phases.
Ø 1. Debugging: It is the process of executing programs on sample data sets to
determine whether faulty results occur and if so to correct them.
Ø 2. Profiling: It is the process of executing a correct program on data sets and
measuring the time and space it takes to compute the results.
15. Structured Programming
Title text
addition
It is a technique for organizing and coding computer programs in which a
hierarchy of modules is used, each having a single entry and a single exit
point, and in which control is passed downward through the structure
without unconditional branches to higher levels of the structure. Three types
of control flow are used: sequential, selection and iteration.
16. Structured Programming- Advantages
Title text
addition
1. It is easy to write as Modular design increases the programmer's productivity by allowing
them to look at the big picture first and focus on details later. Several Programmers can work
on a single, large program, each working on a different module. Structured programs take less
time to write than standard programs.Procedures written for one program can be reused in
other programs requiring the same task.
2. It is easy to debug as each procedure is specialized to perform just one task, a procedure can
be checked individually. Older unstructured programs consist of a sequence of instructions that
are not grouped for specific tasks. The logic of such programs is cluttered with details and
therefore difficult to follow.
3. They are user friendly and easy to understand. The relationship between the procedures
shows the modular design of the program.Meaningful procedure names and clear
documentation identify the task performed by each module. Meaningful variable names help
the programmer identify the purpose of each variable.
17. Structured Programming- Advantages
Title text
addition
4. It is easy to maintain and accommodate changes as a correctly written structured program is
self-documenting, it can be easily understood by another programmer.
5. These are mainly problem oriented rather than machine based.
6. Program written in a higher level language can be translated into many machine languages
and therefore can run on any computer for which there exists an appropriate translator.
7. It is independent of machine on which it is used i.e. programs developed in high level
languages can be run on any computer.
18. Structured Programming- Disadvantages
Title text
addition
1.A high level language has to be translated into the machine language by translator and thus a
price in computer time is paid.
2. The object code generated by a translator might be inefficient compared to an equivalent
assembly language program.
3. Data type are proceeds in many functions in a structured program. When changes occur in
those data types, the corresponding change must be made to every location that acts on those
data types within the program. This is really a very time consuming task if the program is very
large.
4. In case of software development in which several programmers work as a team on an
application. In a structured program, each programmer is assigned to build a specific set of
functions and data types. Since different programmers handle separate functions that have
mutually shared data type. Other programmers in the team must reflect the changes in data
types done by the programmer in data type handled. Otherwise, it requires rewriting several
functions.
19. Control Structures used in writing algorithm
Title text
addition
1. Comments begin with //
2. Blocks are indicated with matching braces {}.Statements are delimited by ;
3. An identifier begins with a letter. The data types of the variables are not explicitly declared
4. Assignment variable := expression;
5. Logical operators – and, or a and not
6. Relational operators - < <= > >= *
20. Control Structures used in writing algorithm
Title text
addition
7. Loops – for, while and repeat and until
while loop :
while ( condition ) do
{
statement 1;
statement 2;
---
---
statement n;
}
21. Control Structures used in writing algorithm
Title text
addition
for loop :
for variable := value 1 to value 2 step n do
{
statement 1;
statement 2;
----
----
statement n;
}
22. Control Structures used in writing algorithm
Title text
addition
repeat…until :
repeat
statement 1;
statement 2;
----
----
statement n;
until(condition)
23. Control Structures used in writing algorithm
Title text
addition
8. Conditional statements
If (condition) then statement
If (condition) then statement1 else statement2
case
{
:condition 1 : statement1
---
---
:condition n : statement n
: else statement n+1
}
24. Control Structures used in writing algorithm
Title text
addition
9. Input and output using read and write
10. Type of procedure .Algorithm name(parameter list)