Time and Space complexity
Time and Space complexity
Prof. P. T. Sawant
Asst. Prof.
Department of Computer Science & Information
Technology
Agenda
Review
Efficiency
Assignment
TIME AND SPACE COMPLEXITY
• Complexity of algorithm is a function of size of input of a
given problem instance which determines how much running
time/memory space is needed by the algorithm in order to
run to completion.
1. Time Complexity: Time complexity of an algorithm is the
amount of time it needs in order to run to completion.
2. Space Complexity: Space Complexity of an algorithm is the
amount of space it needs in order to run to completion.
There are two points which we should consider about computer
programming:-
(i) An appropriate data structure and
(ii) An appropriate algorithm.
Growth of functions
• Algorithms have a primary parameter N that affects the
running time most significantly
– N typically represents the size of the input– e.g., file size, no. of
chars in a string; etc.
• Commonly encounterd running times are proportional to
the following functions
– 1 :Represents a constant
– Log N :Logarithmic
– N :Linear time
– N log N :Linearithmic(?)
– N2 :Quadratic
– N3 :Cubic
– 2N :Exponential
Some common functions
lg N N 0.5 N N lg N N (lg N ) 2 N2 2N