3. INTRODUCTION
•The word algorithm comes from the name of Persian author, Abu Ja’far
Mohammed ibn Musa al Khowarizmi, who wrote a textbook on mathematics.
•Algorithm” refer to a method that can be used by a computer for the solution of
a problem.
4. Definition of Algorithms
Definition: An algorithm is a finite set of unambiguous instruction that if
followed accomplishes a particular task
• An algorithm should have finite number of steps
• It should accept Input and produce desired output
• Algorithm should terminate
5. An algorithm should satisfy the following
criteria
• Input: Algorithm should have Zero or more inputs
• Output: The algorithm should produce correct output
• Definiteness: Each instruction should be clear and unambiguous.
• Finiteness: The algorithm must terminate after finite number of steps.
• Effectiveness: The instructions should be simple and should transform given
input to desired output
• A program is an expression of algorithm in a programming language
6. Algorithm Specification
• We can use natural languages like English
• Graphic representation is called flow chart
• Another representation is Pseudocode that resembles C or Pascal
7. 1. Comments begin with //
2. Blocks are indicated with matching braces {
}
3. An identifier begins with a letter
4. Simple data types like integer, char, float,
Boolean(True or False) can be used
5. Assignment of values to variables is done
using the assignment statement
< variable> :=<expression> or
< variable> <expression>
6. Logical operators (and, or, not )and the
relational operators <, ≤, =,≠,>, ≥ are
provided
Algorithm Specification
8. 7. The following looping statements are employed:
for, while, repeat-until
8. The following conditional statements can be
used
If……. Then….
if …….then……else……
9. 9. Array indices starts at zero, array elements are
represented using [] eg: A[i]
10. Inputs and outputs are done using the
instructions read and write
11. There is only one procedure: Algorithm
the heading takes the form
Algorithm Name ( parameter list)
15. How to Analyze Algorithms
• Analysis of Algorithm or performance analysis refers to the task of determining
how much computing time and storage an algorithm requires.
• It involves 2 phases
1.Priori analysis
2.Posterior analysis
• Priori analysis: Algorithms computing time is obtained in terms of order of
magnitude
• Posterior analysis: Statistics about the algorithm in terms of space and time is
obtained during execution
• This is a challenging area which some times requires great mathematical skill
16. Testing
Testing consists of two phases
• Debugging:
- The process of executing the program on sample data sets and verify if
correct results are obtained.
• Profiling or performance measurement
- The process of executing a correct program on data set and measuring the
time and space it take to compute the result
17. Analysis of algorithms
Efficiency of algorithm depends on
1.Space efficiency
2.Time efficiency
Space Efficiency: It is the amount of memory required to run the program
completely and efficiently.
Space complexity depends on:
- Program space: space required to store the compiled program.
- Data space: Space required to store the constants variables.
Stack space: Space required to store return address , parameters passed etc.
18. Time complexity
• The time T(P) taken by a program is the sum of the compile time and runtime.
• We may assume that a compiled program will run several times without
recompilation
• Consequently we consider only the run time of the program. This runtime is
denoted as tp. .
19. Contd..
Time efficiency: Measure of how fast algorithm executes
Time complexity depends on:
• Speed of computer
• Choice of programming language
• Compiler used
• Choice of algorithm
• Number of inputs/outputs
• Operations count and Steps count
Time efficiency mainly depends on size of input n, hence expressed in terms of n.
20. Order of growth
The efficiency of algorithm can be analyzed by considering highest order of n.
21. Asymptotic notations
Asymptotic notations are used to compare the order of growth of algorithms.
The three notations used are
1. Big oh (O) notation
2. Big omega ( ) notation
3. Big theta ( )notation
22. Big O
Big-O, commonly written as O, is an Asymptotic Notation for the worst case, or ceiling of growth
for a given function.
A function t (n) is said to be in O(g(n)), denoted t (n) ∈ O(g(n)),
if t (n) is bounded above by some constant multiple of g(n) for all large n,
i.e., if there exist some positive constant c
and some nonnegative integer n0 such that
t (n) ≤ cg(n) for all n ≥ n0.
23. Big-Omega
•commonly written as Ω, is an Asymptotic Notation for the best case, or a floor growth rate for a
given function.
• It provides us with an asymptotic lower bound for the growth rate of runtime of an algorithm.
•A function t (n) is said to be in Ω(g(n)), denoted t (n) ∈ Ω(g(n)),
if t (n) is bounded below by some positive constant
multiple of g(n) for all large n, i.e., if there exist some
positive constant c and some nonnegative integer n0
Such that
t (n) ≥ cg(n) for all n ≥ n0.
24. Big Theta:
•A function t (n) is said to be in θ(g(n)), denoted t (n) ∈ θ(g(n)),
if t (n) is bounded both above and below by some positive constant multiples of
g(n) for all large n, i.e., if there exist some positive constants c1 and c2 and some
nonnegative integer n0 such that
c2g(n) ≤ t (n) ≤ c1g(n) for all n ≥ n0