UCSE010 - DESIGN AND ANALYSIS OF ALGORITHMS
1
Dr.Nisha Soms/SRIT
Semester-06/2020-2021
• There are three types of analysis that we
perform on a particular algorithm.
• Best Case indicates the minimum time required for
program execution.
• For example, the best case for a sorting algorithm would be
data that's already sorted.
2
Dr.Nisha Soms/SRIT
• Average Case indicates the average time required for
program execution.
• Finding average case can be very difficult.
• Worst Case indicates the maximum time required for
program execution.
• For example, the worst case for a sorting algorithm might
be data that's sorted in reverse order (but it depends on the
particular algorithm).
3
Dr.Nisha Soms/SRIT
4
Dr.Nisha Soms/SRIT
Ref: https://www.cse.iitd.ac.in/~mausam/courses/col106/autumn2017/lectures/02-
asymptotic.pdf
 The standard notations used to define the time
required and the space required by the algorithm.
 The word Asymptotic means approaching a value or
curve arbitrarily closely (i.e., as some sort of limit is
taken).
 There are three types of asymptotic notations to
represent the growth of any algorithm, as input
increases:
▪ Big Theta (Θ)
▪ Big Oh(O)
▪ Big Omega (Ω)
5
Dr.Nisha Soms/SRIT
6
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 f(n) is O(g(n)), if there exists constants c and
n0 , s.t. f(n) ≤ c g(n) for all n ≥ n0
 f(n) and g(n) are functions over non-negative
integers
7
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 The notation Ο(n) is the formal way to express
the upper bound of an algorithm's running
time.
 It measures the worst case time complexity
or the longest amount of time an algorithm can
possibly take to complete.
8
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 f(n) is Ω(g(n)) if there exists constants c and
n0, such that c g(n) ≤ f(n) for n ≥ n 0
9
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 The notation Ω(n) is the formal way to express
the lower bound of an algorithm's running
time.
 It measures the best case time complexity or
the best amount of time an algorithm can
possibly take to complete.
1
0
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 f(n) is Ɵ(g(n)) if there exists constants c1 , c2 ,
and n0, such that c1 g(n) ≤ f(n) ≤ c2 g(n) for n
≥ n0
1
1
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 The notation θ(n) is the formal way to express
both the lower bound and the upper bound of
an algorithm's running time.
 It measures the average case time complexity
average amount of time an algorithm can
possibly take to complete.
 Given f(n) and g(n), which grows faster?
 If Lim n→∞ f(n)/g(n) = 0, then g(n) is faster
 If Lim n→∞ f(n)/g(n) = ∞, then f(n) is faster
 If Lim n→∞ f(n)/g(n) = non-zero constant,
then both grow at the same rate
 Solved Problems are available in
https://www.cse.wustl.edu/~sg/CS241_FL99/h
w1-practice.html
Semester-06/2020-2021 Dr.Nisha Soms/SRIT 12
1
3
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 General Property:
If f(n) is O(g(n)) then a*f(n) is also O(g(n)) ; where a is a
constant.
 Example:
f(n) = 2n²+5 is O(n²) then 7*f(n) = 7(2n²+5)
= 14n²+35 is also O(n²)
 Similarly, this property satisfies both Θ and Ω notation.
 We can say
 If f(n) is Θ(g(n)) then a*f(n) is also Θ(g(n)); where a is a constant.
 If f(n) is Ω (g(n)) then a*f(n) is also Ω (g(n)); where a is a
constant.
1
4
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 Reflexive Property:
If f(n) is given then f(n) = O(f(n))
 Example:
If f(n) = n3 ⇒ O(n3)
 Similarly,
 f(n) = Ω(f(n))
 f(n) = Θ(f(n))
1
5
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 Transitive Property:
If f(n) is O(g(n)) and g(n) is O(h(n)) then f(n) =
O(h(n)) .
 Example: if f(n) = n , g(n) = n² and h(n)=n³
n is O(n²) and n² is O(n³) then n is O(n³)
 Similarly this property satisfies for both Θ and Ω
notation.
 We can say
 If f(n) is Θ(g(n)) and g(n) is Θ(h(n)) then f(n) = Θ(h(n))
 If f(n) is Ω (g(n)) and g(n) is Ω (h(n)) then f(n) = Ω (h(n))
1
6
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 Symmetric Property:
If f(n) is Θ(g(n)) then g(n) is Θ(f(n)) .
 Example: f(n) = n² and g(n) = n² then f(n) =
Θ(n²) and g(n) = Θ(n²)
This property only satisfies for Θ notation.
1
7
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 Transpose Symmetric Property:
If f(n) is O(g(n)) then g(n) is Ω (f(n)).
 Example: f(n) = n , g(n) = n² then n is O(n²)
and n² is Ω (n)
This property only satisfies for O and Ω
notations.
1
8
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 Transpose Symmetric Property:
If f(n) is O(g(n)) then g(n) is Ω (f(n)).
 Example: f(n) = n , g(n) = n² then n is O(n²)
and n² is Ω (n)
This property only satisfies for O and Ω
notations.
1
9
Semester-06/2020-2021 Dr.Nisha Soms/SRIT
 If f(n) = O(g(n)) and f(n) = Ω(g(n)) then f(n) = Θ(g(n))
 If f(n) = O(g(n)) and d(n)=O(e(n))
then f(n) + d(n) = O( max( g(n), e(n) ))
 Example: f(n) = n i.e O(n), d(n) = n² i.e O(n²)
then f(n) + d(n) = n + n² i.e O(n²)
 If f(n)=O(g(n)) and d(n)=O(e(n)) then
f(n) * d(n) = O( g(n) * e(n) )
 Example: f(n) = n i.e O(n), d(n) = n² i.e O(n²)
then f(n) * d(n) = n * n² = n³ i.e O(n³)
 Solved Problems are available in
https://www.cse.wustl.edu/~sg/CS241_FL99/h
w1-practice.html
Semester-06/2020-2021 Dr.Nisha Soms/SRIT 20
 https://dotnettutorials.net/lesson/properties-of-
asymptotic-notations/
 https://unacademy.com/lesson/properties-of-
asymptotic-notation-part-1/1F2FTIU0
 https://www.cse.iitd.ac.in/~mausam/courses/col1
06/autumn2017/lectures/02-asymptotic.pdf
 https://www.cse.iitd.ac.in/~pkalra/col100/slides/1
0-Efficiency.pdf
 https://www.cse.wustl.edu/~sg/CS241_FL99/hw1
-practice.html
Semester-06/2020-2021 Dr.Nisha Soms/SRIT 21
Please Click Like, Share and Subscribe !
Semester-06/2020-2021 Dr.Nisha Soms/SRIT 22

Asymptotic analysis

  • 1.
    UCSE010 - DESIGNAND ANALYSIS OF ALGORITHMS 1 Dr.Nisha Soms/SRIT Semester-06/2020-2021
  • 2.
    • There arethree types of analysis that we perform on a particular algorithm. • Best Case indicates the minimum time required for program execution. • For example, the best case for a sorting algorithm would be data that's already sorted. 2 Dr.Nisha Soms/SRIT
  • 3.
    • Average Caseindicates the average time required for program execution. • Finding average case can be very difficult. • Worst Case indicates the maximum time required for program execution. • For example, the worst case for a sorting algorithm might be data that's sorted in reverse order (but it depends on the particular algorithm). 3 Dr.Nisha Soms/SRIT
  • 4.
  • 5.
     The standardnotations used to define the time required and the space required by the algorithm.  The word Asymptotic means approaching a value or curve arbitrarily closely (i.e., as some sort of limit is taken).  There are three types of asymptotic notations to represent the growth of any algorithm, as input increases: ▪ Big Theta (Θ) ▪ Big Oh(O) ▪ Big Omega (Ω) 5 Dr.Nisha Soms/SRIT
  • 6.
    6 Semester-06/2020-2021 Dr.Nisha Soms/SRIT f(n) is O(g(n)), if there exists constants c and n0 , s.t. f(n) ≤ c g(n) for all n ≥ n0  f(n) and g(n) are functions over non-negative integers
  • 7.
    7 Semester-06/2020-2021 Dr.Nisha Soms/SRIT The notation Ο(n) is the formal way to express the upper bound of an algorithm's running time.  It measures the worst case time complexity or the longest amount of time an algorithm can possibly take to complete.
  • 8.
    8 Semester-06/2020-2021 Dr.Nisha Soms/SRIT f(n) is Ω(g(n)) if there exists constants c and n0, such that c g(n) ≤ f(n) for n ≥ n 0
  • 9.
    9 Semester-06/2020-2021 Dr.Nisha Soms/SRIT The notation Ω(n) is the formal way to express the lower bound of an algorithm's running time.  It measures the best case time complexity or the best amount of time an algorithm can possibly take to complete.
  • 10.
    1 0 Semester-06/2020-2021 Dr.Nisha Soms/SRIT f(n) is Ɵ(g(n)) if there exists constants c1 , c2 , and n0, such that c1 g(n) ≤ f(n) ≤ c2 g(n) for n ≥ n0
  • 11.
    1 1 Semester-06/2020-2021 Dr.Nisha Soms/SRIT The notation θ(n) is the formal way to express both the lower bound and the upper bound of an algorithm's running time.  It measures the average case time complexity average amount of time an algorithm can possibly take to complete.
  • 12.
     Given f(n)and g(n), which grows faster?  If Lim n→∞ f(n)/g(n) = 0, then g(n) is faster  If Lim n→∞ f(n)/g(n) = ∞, then f(n) is faster  If Lim n→∞ f(n)/g(n) = non-zero constant, then both grow at the same rate  Solved Problems are available in https://www.cse.wustl.edu/~sg/CS241_FL99/h w1-practice.html Semester-06/2020-2021 Dr.Nisha Soms/SRIT 12
  • 13.
    1 3 Semester-06/2020-2021 Dr.Nisha Soms/SRIT General Property: If f(n) is O(g(n)) then a*f(n) is also O(g(n)) ; where a is a constant.  Example: f(n) = 2n²+5 is O(n²) then 7*f(n) = 7(2n²+5) = 14n²+35 is also O(n²)  Similarly, this property satisfies both Θ and Ω notation.  We can say  If f(n) is Θ(g(n)) then a*f(n) is also Θ(g(n)); where a is a constant.  If f(n) is Ω (g(n)) then a*f(n) is also Ω (g(n)); where a is a constant.
  • 14.
    1 4 Semester-06/2020-2021 Dr.Nisha Soms/SRIT Reflexive Property: If f(n) is given then f(n) = O(f(n))  Example: If f(n) = n3 ⇒ O(n3)  Similarly,  f(n) = Ω(f(n))  f(n) = Θ(f(n))
  • 15.
    1 5 Semester-06/2020-2021 Dr.Nisha Soms/SRIT Transitive Property: If f(n) is O(g(n)) and g(n) is O(h(n)) then f(n) = O(h(n)) .  Example: if f(n) = n , g(n) = n² and h(n)=n³ n is O(n²) and n² is O(n³) then n is O(n³)  Similarly this property satisfies for both Θ and Ω notation.  We can say  If f(n) is Θ(g(n)) and g(n) is Θ(h(n)) then f(n) = Θ(h(n))  If f(n) is Ω (g(n)) and g(n) is Ω (h(n)) then f(n) = Ω (h(n))
  • 16.
    1 6 Semester-06/2020-2021 Dr.Nisha Soms/SRIT Symmetric Property: If f(n) is Θ(g(n)) then g(n) is Θ(f(n)) .  Example: f(n) = n² and g(n) = n² then f(n) = Θ(n²) and g(n) = Θ(n²) This property only satisfies for Θ notation.
  • 17.
    1 7 Semester-06/2020-2021 Dr.Nisha Soms/SRIT Transpose Symmetric Property: If f(n) is O(g(n)) then g(n) is Ω (f(n)).  Example: f(n) = n , g(n) = n² then n is O(n²) and n² is Ω (n) This property only satisfies for O and Ω notations.
  • 18.
    1 8 Semester-06/2020-2021 Dr.Nisha Soms/SRIT Transpose Symmetric Property: If f(n) is O(g(n)) then g(n) is Ω (f(n)).  Example: f(n) = n , g(n) = n² then n is O(n²) and n² is Ω (n) This property only satisfies for O and Ω notations.
  • 19.
    1 9 Semester-06/2020-2021 Dr.Nisha Soms/SRIT If f(n) = O(g(n)) and f(n) = Ω(g(n)) then f(n) = Θ(g(n))  If f(n) = O(g(n)) and d(n)=O(e(n)) then f(n) + d(n) = O( max( g(n), e(n) ))  Example: f(n) = n i.e O(n), d(n) = n² i.e O(n²) then f(n) + d(n) = n + n² i.e O(n²)  If f(n)=O(g(n)) and d(n)=O(e(n)) then f(n) * d(n) = O( g(n) * e(n) )  Example: f(n) = n i.e O(n), d(n) = n² i.e O(n²) then f(n) * d(n) = n * n² = n³ i.e O(n³)
  • 20.
     Solved Problemsare available in https://www.cse.wustl.edu/~sg/CS241_FL99/h w1-practice.html Semester-06/2020-2021 Dr.Nisha Soms/SRIT 20
  • 21.
     https://dotnettutorials.net/lesson/properties-of- asymptotic-notations/  https://unacademy.com/lesson/properties-of- asymptotic-notation-part-1/1F2FTIU0 https://www.cse.iitd.ac.in/~mausam/courses/col1 06/autumn2017/lectures/02-asymptotic.pdf  https://www.cse.iitd.ac.in/~pkalra/col100/slides/1 0-Efficiency.pdf  https://www.cse.wustl.edu/~sg/CS241_FL99/hw1 -practice.html Semester-06/2020-2021 Dr.Nisha Soms/SRIT 21
  • 22.
    Please Click Like,Share and Subscribe ! Semester-06/2020-2021 Dr.Nisha Soms/SRIT 22