Unit1 Introduction of Algorithm KCS503
Unit1 Introduction of Algorithm KCS503
Definition:
So, to solve any given problem, we first have to define the problem and then
design and analyse the algorithm required to solve that problem.
Example of an Algorithm:
Algorithm to add two numbers and store the result in a third variable.
Step1: Start
Step4: Perform the addition of num1 and num2 and store the result in variable
“sum”.
Step6: Stop
An algorithm must have the following properties:
1. Finiteness: It means that the algorithm must complete its execution after
some finite number of steps.
2. Definiteness: Each steps of the algorithm must be precisely defined and
unambiguous.
3. Completeness or Generality: Algorithm should be complete so that it can
solve all the problems of the same type for which it is being designed.
4. Effectiveness: All the instructions and operations used in the algorithm
should be simple and feasible so that the algorithm can be implemented in
any programming language on the computer system.
5. Input: An algorithm must have 0 or well defined input for execution.
6. Output: An algorithm must give at least one output.
7. Correctness: The algorithm should produce the output based on the
requirement of the algorithm.
8. Efficient – Efficiency of an algorithm is measured in terms of time and
space complexity for implementing the algorithm. The algorithm should take
less running time and memory space for its execution.
Complexity of Algorithm
It is very convenient to classify algorithm based on the relative amount of time
or relative amount of space they required and specify the growth of time/space
requirement as a function of input size.
1. Time Complexity: Running time of a program as a function of the size of
the input.
2. Space Complexity: Some forms of analysis could be done based on how
much space an algorithm needs to complete its task. This space complexity
analysis was critical in the early days of computing when storage space on
the computer was limited. When considering this algorithm are divided into
those that need extra space to do their work and those that work in place.
But now a day's problem of space rarely occurs because space on the computer
(internal or external) is enough.