You are on page 1of 14

Algorithm And Space Complexity

1
Course Name : DATA STRUCTURES USING C

Course Teacher : Subrata Sahana


Assistant Professor, Dept. of Computer Science

2
Outline (Module-1)
1. Introduction to Algorithm
2. Example of Algorithm
3. Complexity of Algorithm
4. Space Complexity
5. Examples of Space Complexity

3
Book

1. “Theory
and Problems of Data Structures”
by Seymour Lipschutz, McGraw-Hill,
ISBN 0-07-038001-5.

4
Introduction to Algorithm
Example of Algorithm
Complexity of Algorithm

Two types of Complexity


1. Space Complexity
2. Time Complexity
Space Complexity

The space complexity of an algorithm is


the amount of memory it needs to run to
completion.
Each algorithm has
Fixed Part
Variable Part

8
Cont…

9
Example 1: Algorithm 1

10
Example 2: Algorithm 2

11
Example 3: Algorithm 3

12
Algorithm Analysis:
An algorithm is a finite set of instructions that, if followed,
accomplishes a particular task. In addition, all algorithms must satisfy
the following criteria.
Input
Output
Definiteness
Finiteness
Effectiveness
 
The criteria 1 & 2 require that an algorithm produces one or more
outputs & have zero or more input. According to criteria 3, each
operation must be definite such that it must be perfectly clear what
should be done. According to the 4th criteria algorithm should
terminate after a finite no. of operations. According to 5th criteria,
every instruction must be very basic so that it can be carried out by a
person using only pencil & paper.
There may be many algorithms devised for an application and we
must analyse and validate the algorithms to judge the suitable one.
 
To judge an algorithm the most important factors is to have a direct
relationship to the performance of the algorithm. These have to do
with their computing time & storage requirements ( referred as Time
complexity & Space complexity).

Space Complexity:
The space complexity of an algorithm is the amount of memory it
needs to run.
 
Time Complexity:
The time taken by a program is the sum of the compiled time & the
run time. The time complexity of an algorithm is given by the
number of steps taken by the algorithm to compute the function it
was written for.

You might also like