1. What is Algorithm?
2. Characteristics of Algorithms
Properties of Algorithm
What is an Algorithm ?
1. What is Algorithm?
2. Characteristics of Algorithms
Properties of Algorithm
What is an Algorithm ?
Properties of Algorithm
What is an Algorithm ?
An algorithm is a
is a sequence of unambiguous instructions for solving a problem, to obtain
a required output for any legitimate input in a finite amount of time.
1. What is Algorithm?
2. Characteristics of Algorithms
Properties of Algorithm
What is an Algorithm ?
Characteristics of an Algorithm
1. Input:
2. Output:
3. Finiteness:
4. Definiteness:
5. Effectiveness:
6. Generality:
Simply writing the sequence of instructions as an algorithm is not sufficient to
accomplish certain task. It is necessary to have following properties associated
with an algorithm.
Properties of Algorithm
Problem
Statement
Algorithm
Design
Program
Programming
Language
Statements
C/C++
Statements
Analysing
Algorithm
Correctness
of
Algorithm
Algorithm Design and Analysis
Analysis 2
Analysis 1
Solving a Problem With a Computer
Algorithmic Problem Solving
Algorithm
Design
1. Input:
2. Output:
3. Finiteness:
4. Definiteness:
5. Effectiveness:
6. Generality:
Characteristics of an Algorithm Properties of Algorithm
The range of values for which an algorithm works has to be specified carefully
1. Input
This algorithm does not work correctly when one of its input
numbers is zero.
This illustrates why it is so important to specify the set of an
algorithm’s inputs explicitly and carefully.
GCD ( m , n )
t = min(m, n)
while (t<=0) {
if (m % t = 0){
if (n % t = 0)
return t;
}
t = t – 1;
}
Greatest Common Divisor : (Consecutive Integer Checking Algorithm)
Every algorithm has zero or more inputs:
these inputs are taken from specified set of objects.
Here, two inputs m and n are taken from the set of positive
integers.
Therefore,
Properties of Algorithm
1. Input:
2. Output:
3. Finiteness:
4. Definiteness:
5. Effectiveness:
6. Generality:
Characteristics of an Algorithm Properties of Algorithm
From each set of input values, an algorithm produces output values from
a specified set.
An algorithm has one or more outputs:
The algorithm must clearly define what output will be yielded and it should
be well-defined as well.
1. Output Properties of Algorithm
Characteristics of an Algorithm Properties of Algorithm
1. Input:
2. Output:
3. Finiteness:
4. Definiteness:
5. Effectiveness:
6. Generality:
3. Finiteness
An algorithm must always terminate after a finite number of steps.
Euclid’s Algorithm
Given two positive integers m and n, find their greatest common divisor.
GCD ( m , n )
Step 1 divide m by n and
let r be the remainder. ( 0 ≤ r < n )
Step 2 if r = 0, terminate, n is the answer
Step 3 Set m n, n r and go back to Step 1
This algorithm satisfies the condition of finiteness, because
 the value of r decreases every time the Step 1 is encountered.
 the value of r becomes 0 after finite number of steps, So, algorithm must terminate
Properties of Algorithm
15
6
Case 1: The lengths of line segments are commensurable
3. Finiteness Properties of Algorithm
Commensurable means
having a common measure
Find the “Greatest Common Measure“ of the two line segments
Example:
15
6
3. Finiteness Properties of Algorithm
Case 1: The lengths of line segments are commensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
9
6
3. Finiteness Properties of Algorithm
Case 1: The lengths of line segments are commensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
9
6
3. Finiteness Properties of Algorithm
Case 1: The lengths of line segments are commensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
3
6
3. Finiteness Properties of Algorithm
Case 1: The lengths of line segments are commensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
3
6
3. Finiteness Properties of Algorithm
Case 1: The lengths of line segments are commensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
3
3
3. Finiteness Properties of Algorithm
Case 1: The lengths of line segments are commensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
3
3
3. Finiteness Properties of Algorithm
Find the “Greatest Common Measure“ of the two line segments
Case 1: The lengths of line segments are commensurable
Example:
3
3. Finiteness
3 is the “Greatest Common Measure“ of the these two line
3. Finiteness Properties of Algorithm
Case 1: The lengths of line segments are commensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
Algorithm must terminate in case of commensurable line segments
So, fulfils the property of Finiteness
 The algorithm does not terminate if the given lengths are incommensurable.
3. Finiteness Properties of Algorithm
Find the “Greatest Common Measure“ of the two line segments
Example:
Incommensurable:
having no common standard of measurement.
Case 2: The lengths of line segments are incommensurable
What if we try to find the “greatest common measure” of the side and the diagonal of a square?
5
5
5
5
Apply Euclidean algorithm to find the “greatest common measure” of the side and the diagonal of a
square.
Here side and diagonal’s lengths are incommensurable.
It doesn’t end.
Case 2: The lengths of line segments are incommensurable
3. Finiteness Properties of Algorithm
Find the “Greatest Common Measure“ of the two line segments
Example:
5
5
5
5
3. Finiteness Properties of Algorithm
Case 2: The lengths of line segments are incommensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
5
5
5
5
3. Finiteness Properties of Algorithm
Case 2: The lengths of line segments are incommensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
5
5
5
5
3. Finiteness Properties of Algorithm
Case 2: The lengths of line segments are incommensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
5
5
5
5
3. Finiteness
3. Finiteness Properties of Algorithm
Case 2: The lengths of line segments are incommensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
5
5
5
5
3. Finiteness Properties of Algorithm
Case 2: The lengths of line segments are incommensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
5
5
5
5
3. Finiteness Properties of Algorithm
Case 2: The lengths of line segments are incommensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
5
5
5
5
3. Finiteness
3. Finiteness Properties of Algorithm
Case 2: The lengths of line segments are incommensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
5
5
5
5
3. Finiteness
3. Finiteness Properties of Algorithm
Case 2: The lengths of line segments are incommensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
5
5
5
5
it doesn’t end.
3. Finiteness Properties of Algorithm
Case 2: The lengths of line segments are incommensurable
Find the “Greatest Common Measure“ of the two line segments
Example:
The algorithm does not terminate if the
given lengths are incommensurable.
So, a method to find Greatest Common Measure of two line segments of incommensurable lengths is
not a legitimate algorithm - It is just a computational method
Violating Finiteness
An algorithm must always terminate after a finite number of steps.
If it is already proven to be correct to the extent that it will produce the desired results and
terminate, then
it is inefficient and needs tuning up.
3. Finiteness Properties of Algorithm
Example 1
Suppose we develop an algorithm to generate all sentences in a language. Every time
a new sentence is generated, it is printed out. Now, as a typical language has an
infinite number of possible sentences, the algorithm as specified will never terminate.
In such cases, the termination condition is understood to mean generation of an
output, which is the inner component of the algorithm, and the main algorithm simply
repeats this sub-algorithm infinite number of times.
This requirement of termination of the algorithm should not be confused with the behavior of algorithms for problems
which themselves may generate infinite output.
Example 2
Interactive program waiting indefinitely for a user input and then giving a response.
In such case, the main algorithm loops continuously, invoking an inner sub-algorithm,
which must prompt the user and give response within a finite time, that is, it should
terminate.
3. Finiteness Properties of Algorithm
Characteristics of an Algorithm Properties of Algorithm
1. Input:
2. Output:
3. Finiteness:
4. Definiteness:
5. Effectiveness:
6. Generality:
The steps of an algorithm must be defined precisely (unambiguously specified)
 Every instruction in an algorithm should have ”one and only one” interpretation.
4. Definiteness
Designer write algorithms, but some other agent (person or computer) will execute them.
So, algorithm should be so clear that the agent can follow it without the intervention of the
others.
 Every step must be clear , well defined and precise. There should be no ambiguity.
- clearly specifying what is meant to be done.
Properties of Algorithm
 Every instruction in an algorithm should have ”one and only one” interpretation.
” Repeat steps 1 to 4 a few times”
Unambiguous:
” Repeat steps 1 to 4 until x is equal to y “
A statement, Like
- ambiguous because
: Different tries by different people
4. Definiteness Properties of Algorithm
The steps of an algorithm must be defined precisely (unambiguously specified)
4. Definiteness
GCD ( m , n )
Step 1 divide m by n and
let r be the remainder. ( 0 ≤ r < n )
Step 2 if r = 0, terminate, n is the answer
Step 3 Set m n, n r and go back to Step 1
Euclid’s Algorithm
Although, most of the text in this algorithm is in
English, still it satisfies definiteness.
As English language is ambiguous,
so there is a possibility that the reader might not understand exactly what the author(designer)
intended.
4. Definiteness Properties of Algorithm
4. Definiteness
In order to achieve definiteness,
instructions must be expressed in some standard language, so they
can be understood by all.
4. Definiteness Properties of Algorithm
Properties of Algorithm
People write algorithms, but some agent (computer or person) will execute them.
So, they must be expressed in some standard language.
It is written in a language which is easy for humans to understand
4. Definiteness
 Natural Language (human language: English, Chinese etc.)
Natural languages are ambiguous languages. There is a possibility that the implementer
might not understand exactly what the designer intended.
 Computer Language (C++, Java etc.)
If we specify the instructions of the algorithms in any Computer language, these
language specific instructions will be difficult to understand, even other language user
couldn’t understand it. Instructions should be programming language independent.
It is written in a language which is easy for humans to understand
Properties of Algorithm
4. Definiteness
 Pseudocode (English+ Programming language notation)
Pseudocode is the best choice to specify algorithms. As algorithms’ instructions
consist of simple statement, conditional statement, and repeat statement (which are
basic for all languages), so they are understandable for all.
As you all know, all programing languages share code constructs such as
Loops (for, while, do while etc.)
Flow Controls (if else etc.)
An algorithm can be written using these constructs.
 Flow Chart (Graphical Way) - another way to write an algorithm
Properties of Algorithm
4. Definiteness
4. Definiteness
While writing instructions in programming language, where you feel difficulty, use English like instructions
for x = 1 to n
” Repeat steps 1 to 4 few times “
do
1. -------
2. -------
while (x = = y)
” Repeat steps 1 to 4 until x = y “
While writing instructions in English, where you feel ambiguity, use programming language instructions.
for (float x=1; x <= n; x++)
” Repeat steps 1 to 4 until x = y “
#1
#2
4. Definiteness Properties of Algorithm
” Sort the numbers”
The computer has no basic operation for Sorting.
- ambiguous because
A statement, Like
It is not easy for the agent to understand this instruction.
In order to avoid this type of ambiguousness, simple basic statements like
- assignments
- finite loop and
- conditional statements
are used in writing algorithms
We have to define Sort
(another algorithm) using
simple basic statements i.e.,
assignments, finite loop and
conditional statements.
Instructions should be clear and straightforward (basic).
4. Definiteness Properties of Algorithm
Characteristics of an Algorithm Properties of Algorithm
1. Input:
2. Output:
3. Finiteness:
4. Definiteness:
5. Effectiveness:
6. Generality:
in the sense that
 they can be done exactly in a finite length of time by someone using pencil and paper.
An algorithm is also generally expected to be effective,
Effective Operations
 its operations must all be sufficiently basic,
These are effective, because
It must be possible to perform each step exactly in a finite amount of time
GCD ( m , n )
Step 1 divide m by n and
let r be the remainder. ( 0 ≤ r < n )
Step 2 if r = 0, terminate, n is the answer
Step 3 Set m n, n r and go back to Step 1
integer can be represented on paper in a finite manner.
 testing if an integer is zero
 division
 setting the variable values
The same operations would not be effective,
if the values involved were arbitrary real numbers specified an infinite decimal expansion.
(can not specify exactly)
5. Effectiveness Properties of Algorithm
Characteristics of an Algorithm Properties of Algorithm
1. Input:
2. Output:
3. Finiteness:
4. Definiteness:
5. Effectiveness:
6. Generality:
6. Generality
The procedure should be applicable for all problems of the desired form, not just for a
particular set of input values.
Properties of Algorithm
1. Input: An algorithm has input values from a specified set (clearly specified Inputs)
2. Output: From each set of input values, an algorithm produces output values from a specified set.
4. Definiteness: The steps of an algorithm must be defined precisely (unambiguously specified)
3. Finiteness: An algorithm should produce the desired output after a finite number of steps
for any input in the set (terminates after a finite number of steps)
5. Effectiveness: It must be possible to perform each step of an algorithm exactly and in a finite amount of time
(steps are sufficiently simple and basic)
6. Generality: The procedure should be applicable for all problems of the desired form, not just for a particular set of
input values.
Characteristics of an Algorithm Properties of Algorithm

2. Characteristics of Algorithm.ppt

  • 1.
    1. What isAlgorithm? 2. Characteristics of Algorithms Properties of Algorithm What is an Algorithm ?
  • 2.
    1. What isAlgorithm? 2. Characteristics of Algorithms Properties of Algorithm What is an Algorithm ?
  • 3.
    Properties of Algorithm Whatis an Algorithm ? An algorithm is a is a sequence of unambiguous instructions for solving a problem, to obtain a required output for any legitimate input in a finite amount of time.
  • 4.
    1. What isAlgorithm? 2. Characteristics of Algorithms Properties of Algorithm What is an Algorithm ?
  • 5.
    Characteristics of anAlgorithm 1. Input: 2. Output: 3. Finiteness: 4. Definiteness: 5. Effectiveness: 6. Generality: Simply writing the sequence of instructions as an algorithm is not sufficient to accomplish certain task. It is necessary to have following properties associated with an algorithm. Properties of Algorithm
  • 6.
    Problem Statement Algorithm Design Program Programming Language Statements C/C++ Statements Analysing Algorithm Correctness of Algorithm Algorithm Design andAnalysis Analysis 2 Analysis 1 Solving a Problem With a Computer Algorithmic Problem Solving Algorithm Design
  • 7.
    1. Input: 2. Output: 3.Finiteness: 4. Definiteness: 5. Effectiveness: 6. Generality: Characteristics of an Algorithm Properties of Algorithm
  • 8.
    The range ofvalues for which an algorithm works has to be specified carefully 1. Input This algorithm does not work correctly when one of its input numbers is zero. This illustrates why it is so important to specify the set of an algorithm’s inputs explicitly and carefully. GCD ( m , n ) t = min(m, n) while (t<=0) { if (m % t = 0){ if (n % t = 0) return t; } t = t – 1; } Greatest Common Divisor : (Consecutive Integer Checking Algorithm) Every algorithm has zero or more inputs: these inputs are taken from specified set of objects. Here, two inputs m and n are taken from the set of positive integers. Therefore, Properties of Algorithm
  • 9.
    1. Input: 2. Output: 3.Finiteness: 4. Definiteness: 5. Effectiveness: 6. Generality: Characteristics of an Algorithm Properties of Algorithm
  • 10.
    From each setof input values, an algorithm produces output values from a specified set. An algorithm has one or more outputs: The algorithm must clearly define what output will be yielded and it should be well-defined as well. 1. Output Properties of Algorithm
  • 11.
    Characteristics of anAlgorithm Properties of Algorithm 1. Input: 2. Output: 3. Finiteness: 4. Definiteness: 5. Effectiveness: 6. Generality:
  • 12.
    3. Finiteness An algorithmmust always terminate after a finite number of steps. Euclid’s Algorithm Given two positive integers m and n, find their greatest common divisor. GCD ( m , n ) Step 1 divide m by n and let r be the remainder. ( 0 ≤ r < n ) Step 2 if r = 0, terminate, n is the answer Step 3 Set m n, n r and go back to Step 1 This algorithm satisfies the condition of finiteness, because  the value of r decreases every time the Step 1 is encountered.  the value of r becomes 0 after finite number of steps, So, algorithm must terminate Properties of Algorithm
  • 13.
    15 6 Case 1: Thelengths of line segments are commensurable 3. Finiteness Properties of Algorithm Commensurable means having a common measure Find the “Greatest Common Measure“ of the two line segments Example:
  • 14.
    15 6 3. Finiteness Propertiesof Algorithm Case 1: The lengths of line segments are commensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 15.
    9 6 3. Finiteness Propertiesof Algorithm Case 1: The lengths of line segments are commensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 16.
    9 6 3. Finiteness Propertiesof Algorithm Case 1: The lengths of line segments are commensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 17.
    3 6 3. Finiteness Propertiesof Algorithm Case 1: The lengths of line segments are commensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 18.
    3 6 3. Finiteness Propertiesof Algorithm Case 1: The lengths of line segments are commensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 19.
    3 3 3. Finiteness Propertiesof Algorithm Case 1: The lengths of line segments are commensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 20.
    3 3 3. Finiteness Propertiesof Algorithm Find the “Greatest Common Measure“ of the two line segments Case 1: The lengths of line segments are commensurable Example:
  • 21.
    3 3. Finiteness 3 isthe “Greatest Common Measure“ of the these two line 3. Finiteness Properties of Algorithm Case 1: The lengths of line segments are commensurable Find the “Greatest Common Measure“ of the two line segments Example: Algorithm must terminate in case of commensurable line segments So, fulfils the property of Finiteness
  • 22.
     The algorithmdoes not terminate if the given lengths are incommensurable. 3. Finiteness Properties of Algorithm Find the “Greatest Common Measure“ of the two line segments Example: Incommensurable: having no common standard of measurement. Case 2: The lengths of line segments are incommensurable
  • 23.
    What if wetry to find the “greatest common measure” of the side and the diagonal of a square? 5 5 5 5 Apply Euclidean algorithm to find the “greatest common measure” of the side and the diagonal of a square. Here side and diagonal’s lengths are incommensurable. It doesn’t end. Case 2: The lengths of line segments are incommensurable 3. Finiteness Properties of Algorithm Find the “Greatest Common Measure“ of the two line segments Example:
  • 24.
    5 5 5 5 3. Finiteness Propertiesof Algorithm Case 2: The lengths of line segments are incommensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 25.
    5 5 5 5 3. Finiteness Propertiesof Algorithm Case 2: The lengths of line segments are incommensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 26.
    5 5 5 5 3. Finiteness Propertiesof Algorithm Case 2: The lengths of line segments are incommensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 27.
    5 5 5 5 3. Finiteness 3. FinitenessProperties of Algorithm Case 2: The lengths of line segments are incommensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 28.
    5 5 5 5 3. Finiteness Propertiesof Algorithm Case 2: The lengths of line segments are incommensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 29.
    5 5 5 5 3. Finiteness Propertiesof Algorithm Case 2: The lengths of line segments are incommensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 30.
    5 5 5 5 3. Finiteness 3. FinitenessProperties of Algorithm Case 2: The lengths of line segments are incommensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 31.
    5 5 5 5 3. Finiteness 3. FinitenessProperties of Algorithm Case 2: The lengths of line segments are incommensurable Find the “Greatest Common Measure“ of the two line segments Example:
  • 32.
    5 5 5 5 it doesn’t end. 3.Finiteness Properties of Algorithm Case 2: The lengths of line segments are incommensurable Find the “Greatest Common Measure“ of the two line segments Example: The algorithm does not terminate if the given lengths are incommensurable. So, a method to find Greatest Common Measure of two line segments of incommensurable lengths is not a legitimate algorithm - It is just a computational method Violating Finiteness
  • 33.
    An algorithm mustalways terminate after a finite number of steps. If it is already proven to be correct to the extent that it will produce the desired results and terminate, then it is inefficient and needs tuning up. 3. Finiteness Properties of Algorithm
  • 34.
    Example 1 Suppose wedevelop an algorithm to generate all sentences in a language. Every time a new sentence is generated, it is printed out. Now, as a typical language has an infinite number of possible sentences, the algorithm as specified will never terminate. In such cases, the termination condition is understood to mean generation of an output, which is the inner component of the algorithm, and the main algorithm simply repeats this sub-algorithm infinite number of times. This requirement of termination of the algorithm should not be confused with the behavior of algorithms for problems which themselves may generate infinite output. Example 2 Interactive program waiting indefinitely for a user input and then giving a response. In such case, the main algorithm loops continuously, invoking an inner sub-algorithm, which must prompt the user and give response within a finite time, that is, it should terminate. 3. Finiteness Properties of Algorithm
  • 35.
    Characteristics of anAlgorithm Properties of Algorithm 1. Input: 2. Output: 3. Finiteness: 4. Definiteness: 5. Effectiveness: 6. Generality:
  • 36.
    The steps ofan algorithm must be defined precisely (unambiguously specified)  Every instruction in an algorithm should have ”one and only one” interpretation. 4. Definiteness Designer write algorithms, but some other agent (person or computer) will execute them. So, algorithm should be so clear that the agent can follow it without the intervention of the others.  Every step must be clear , well defined and precise. There should be no ambiguity. - clearly specifying what is meant to be done. Properties of Algorithm
  • 37.
     Every instructionin an algorithm should have ”one and only one” interpretation. ” Repeat steps 1 to 4 a few times” Unambiguous: ” Repeat steps 1 to 4 until x is equal to y “ A statement, Like - ambiguous because : Different tries by different people 4. Definiteness Properties of Algorithm
  • 38.
    The steps ofan algorithm must be defined precisely (unambiguously specified) 4. Definiteness GCD ( m , n ) Step 1 divide m by n and let r be the remainder. ( 0 ≤ r < n ) Step 2 if r = 0, terminate, n is the answer Step 3 Set m n, n r and go back to Step 1 Euclid’s Algorithm Although, most of the text in this algorithm is in English, still it satisfies definiteness. As English language is ambiguous, so there is a possibility that the reader might not understand exactly what the author(designer) intended. 4. Definiteness Properties of Algorithm
  • 39.
    4. Definiteness In orderto achieve definiteness, instructions must be expressed in some standard language, so they can be understood by all. 4. Definiteness Properties of Algorithm
  • 40.
    Properties of Algorithm Peoplewrite algorithms, but some agent (computer or person) will execute them. So, they must be expressed in some standard language. It is written in a language which is easy for humans to understand 4. Definiteness
  • 41.
     Natural Language(human language: English, Chinese etc.) Natural languages are ambiguous languages. There is a possibility that the implementer might not understand exactly what the designer intended.  Computer Language (C++, Java etc.) If we specify the instructions of the algorithms in any Computer language, these language specific instructions will be difficult to understand, even other language user couldn’t understand it. Instructions should be programming language independent. It is written in a language which is easy for humans to understand Properties of Algorithm 4. Definiteness
  • 42.
     Pseudocode (English+Programming language notation) Pseudocode is the best choice to specify algorithms. As algorithms’ instructions consist of simple statement, conditional statement, and repeat statement (which are basic for all languages), so they are understandable for all. As you all know, all programing languages share code constructs such as Loops (for, while, do while etc.) Flow Controls (if else etc.) An algorithm can be written using these constructs.  Flow Chart (Graphical Way) - another way to write an algorithm Properties of Algorithm 4. Definiteness
  • 43.
    4. Definiteness While writinginstructions in programming language, where you feel difficulty, use English like instructions for x = 1 to n ” Repeat steps 1 to 4 few times “ do 1. ------- 2. ------- while (x = = y) ” Repeat steps 1 to 4 until x = y “ While writing instructions in English, where you feel ambiguity, use programming language instructions. for (float x=1; x <= n; x++) ” Repeat steps 1 to 4 until x = y “ #1 #2 4. Definiteness Properties of Algorithm
  • 44.
    ” Sort thenumbers” The computer has no basic operation for Sorting. - ambiguous because A statement, Like It is not easy for the agent to understand this instruction. In order to avoid this type of ambiguousness, simple basic statements like - assignments - finite loop and - conditional statements are used in writing algorithms We have to define Sort (another algorithm) using simple basic statements i.e., assignments, finite loop and conditional statements. Instructions should be clear and straightforward (basic). 4. Definiteness Properties of Algorithm
  • 45.
    Characteristics of anAlgorithm Properties of Algorithm 1. Input: 2. Output: 3. Finiteness: 4. Definiteness: 5. Effectiveness: 6. Generality:
  • 46.
    in the sensethat  they can be done exactly in a finite length of time by someone using pencil and paper. An algorithm is also generally expected to be effective, Effective Operations  its operations must all be sufficiently basic, These are effective, because It must be possible to perform each step exactly in a finite amount of time GCD ( m , n ) Step 1 divide m by n and let r be the remainder. ( 0 ≤ r < n ) Step 2 if r = 0, terminate, n is the answer Step 3 Set m n, n r and go back to Step 1 integer can be represented on paper in a finite manner.  testing if an integer is zero  division  setting the variable values The same operations would not be effective, if the values involved were arbitrary real numbers specified an infinite decimal expansion. (can not specify exactly) 5. Effectiveness Properties of Algorithm
  • 47.
    Characteristics of anAlgorithm Properties of Algorithm 1. Input: 2. Output: 3. Finiteness: 4. Definiteness: 5. Effectiveness: 6. Generality:
  • 48.
    6. Generality The procedureshould be applicable for all problems of the desired form, not just for a particular set of input values. Properties of Algorithm
  • 49.
    1. Input: Analgorithm has input values from a specified set (clearly specified Inputs) 2. Output: From each set of input values, an algorithm produces output values from a specified set. 4. Definiteness: The steps of an algorithm must be defined precisely (unambiguously specified) 3. Finiteness: An algorithm should produce the desired output after a finite number of steps for any input in the set (terminates after a finite number of steps) 5. Effectiveness: It must be possible to perform each step of an algorithm exactly and in a finite amount of time (steps are sufficiently simple and basic) 6. Generality: The procedure should be applicable for all problems of the desired form, not just for a particular set of input values. Characteristics of an Algorithm Properties of Algorithm