0% found this document useful (0 votes)
27 views16 pages

Daa Unit-1 PPT-3

DAA UNIT-1 PPT-3

Uploaded by

kvsreddycse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views16 pages

Daa Unit-1 PPT-3

DAA UNIT-1 PPT-3

Uploaded by

kvsreddycse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

VIDEO-3

DESIGN AND ANALYSIS OF ALGORITHMS


III B.Tech CSE , A.Y:2020-21,SEMESTER-2
JNTUK KAKINADA-R16

KALLAM HARANADHAREDDY INSTITUTE OF


TECHNOLOGY
Dr K Venkata Subba Reddy, Professor&HOD, Department of CSE,KHIT
TOPICS TO BE COVERED IN UNIT-I
Introduction:

 What is an Algorithm
 Algorithm Specification, Pseudo code Conventions
 Recursive Algorithm
 Performance Analysis
 Space Complexity, Time Complexity
 Amortized Complexity
 Asymptotic Notation
 Practical Complexities, Performance Measurement.

2
TIME COMPLEXITY AND SPACE COMPLEXITY

When An algorithm is said to be efficient and fast?


(or)
How to measure the efficiency of algorithm?
Ans: if an algorithm takes less time to execute and
consumes less memory space.

The performance of an algorithm is measured on the


basis of following properties :

1. Time Complexity
2. Space Complexity
3
Space Complexity
Def: Space complexity of an algorithm represents the amount
of memory space required by the algorithm in its life cycle.
Space complexity S(P) of any algorithm
P is
S(P) = C + SP(I)
where C is the fixed part and
S(I) is the variable part of the algorithm, which depends
on instance characteristic I

A fixed part that is a space required to store certain data and


variables, that are independent of the size of the problem. For
example, simple variables and constants used, program size, etc.
A variable part is a space required by variables, whose size depends
on the size of the problem. 4
SPACE COMPLEXITY
Let P be the algorithm

Let S(P) be the space requirement for algorithm

Then

S(P)=C+Sp
Where
C is the Fixed Space
where as
Sp is the Variable Space (Space may Vary )
5
Space Complexity-Example
Algorithm Sum(A, n) //algorithm heading part requires zero units of
space
{ //Open brace requires zero units of space
S:=0; //Variable S requires One unit of space
for i=1 to n // Variable i, n requires one Unit of space
each
s=s+a[i]; //array a[i] requires n units of space
return s; //Variable S requires one unit of space
} // Close brace requires Zero units of space
Space Complexity of an algorithm is S(P)=C+Sp

C= Constant space=1+1+1=3 (Variables n, s, i required


one unit of space or memory so n=1,s=1,i=1)
Sp=Variable Space=n (Since a[i] required n spaces) 6
TIME COMPLEXITY
Time Complexity is calculated as

Time Complexity=Compile Time+ Run Time

T(n)=C+Rp
Where as
Time Complexity=T(n)
Compile Time=C
Runtime=Rp

7
Time Complexity-Example 1

Time Complexity on an algorithm T(n)=O(n)


8
Time Complexity-Example 2

Time complexity of an algorithm is : mn


(Consider highest coefficient value among mn+m)
9
Time Complexity
Usually, the time required by an algorithm falls under
three types −

Best Case − Minimum time required for program execution.


Average Case − Average time required for program
execution.
Worst Case − Maximum time required for program
For example: In bubble sort, when the input array is already
execution.
sorted, the time taken by the algorithm is linear i.e. the best
case.
But, when the input array is in reverse condition, the algorithm
takes the maximum time to sort the elements i.e. the worst
case.
When the input array is neither sorted nor in reverse order, then it
takes average time. These durations are denoted using 10
ASYMPTOTIC NOTATIONS
Def: Analyzing the complexity of any algorithm in terms of
time and space, we can never provide an exact number to
define the time required and the space required by the
algorithm,

instead we express it using some standard notations, also


known as Asymptotic Notations.

Types of Asymptotic Notations


Three types of asymptotic notations to represent the growth
of any algorithm, as input increases:

1. Big Oh (O) --Upper Bound


2. Big Omega (Ω) -- Lower Bound
3. Big Theta (Θ) -- Average Bound 11
Asymptotic Notations: Big-O Notation

1. Big-O notation represents the


upper bound of the running time of an
algorithm.

2. Thus, it gives the worst-case


complexity of an algorithm.

Definition:
Let f(n) define running time of an
algorithm
The function f(n)=O(g(n)) if and only if,
there exist all positive constants C and n 0,
such that f(n)<=C*g(n) for all, n>= n0 12
Asymptotic Notations: Omega- Ω Notation

1. Ω notation represents the lower bound


of the running time of an algorithm.

2. Thus, it gives the Best-case complexity


of an algorithm.

Definition:
Let f(n) define running time of an
algorithm
The function f(n)= Ω(g(n)) if and only if,
there exist all positive constants C and n 0,
such that f(n)>=C*g(n) for all, n>= n0
13
Asymptotic Notations: Theta- Θ Notation
1. Θ notation represents the average
bound of the running time of an
algorithm.

2. Thus, it gives the Average-case


complexity of an algorithm.

Definition:
Let f(n) define running time of an
algorithm
The function f(n)= Θ(g(n)) if and only if,
there exist all positive constants C 1 and
IfCa2 function
andf(n) lies
n0anywhere
, in such
between c1that
g(n) and c2g(n) for all n ≥ n0,
then f(n) is said to be asymptotically tight bound. 14
C1*g(n)<=f(n)<=C2*g(n) for all, n>= n0
Asymptotic Notations: Definitions

15
THANK YOU

16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy