You are on page 1of 13

Design and analysis of algorithms

Lecture 2
Aditya Harbola

10-07-2020
Table of contents
• Function
• Growth of functions
• Time Complexity
• Space complexity
• Asymptotic notations

10-07-2020
Function
• In mathematics, a function is a binary relation
over two sets that associates to every element
of the first set exactly one element of the
second set.
• f(n)= 1
• f(n)=log n
• f(x)=x+10
• f(n)=n!
10-07-2020
10-07-2020
Growth of functions
• The growth of functions is a term to calculate
the growth for different input values.
• The growth of functions is directly related to
the complexity of algorithms.

10-07-2020
10-07-2020
Why GoF
• It is the order of growth of the running time
of an algorithm.
• In order to get a handle on its complexity, we
first look for a function that gives the number
of operations in terms of the size of the
problem, usually measured by a positive
integer n, to which the algorithm is applied.

10-07-2020
Complexity of an algorithm
• Complexity of an algorithm is a measure of
the amount of time and/or space required by
an algorithm for an input of a given size (n).
• Ex: Linear search time complexity is O(n) and
space complexity is O(1)

10-07-2020
Time and space complexity
• Time complexity of an algorithm quantifies
the amount of time taken by an algorithm to
run as a function of the length of the input.

• Space complexity of an algorithm quantifies


the amount of space or memory taken by an
algorithm to run as a function of the length of
the input.

10-07-2020
• Algorithm complexity is a rough
approximation of the number of steps, which
will be executed depending on the size of the
input data. Complexity gives the order of steps
count, not their exact count.
• If we have an order of N2 operations to
process N elements, then N2/2 and 3*N2 are
of one and the same quadratic order.

10-07-2020
Best, Worst and Average Case
• Searching in array N elements (Linear search)
• In the best case we will have luck and we will
find the element at first position. O(1)
• In the average case we can expect to check
half the elements in the array until we find the
one we are looking for. O(N/2)=O(N)
• To find the searched key in the worst case, we
have to check all the elements in the array.
O(N)
10-07-2020
10-07-2020
Asymptotic notations
• Asymptotic notations are the
mathematical notations used to describe the
running time of an algorithm
• We use three types of asymptotic
notations to represent the growth of any
algorithm, as input increases:
• Big Theta (Θ)
• Big Oh(O)
• Big Omega (Ω)
10-07-2020

You might also like