SlideShare a Scribd company logo
1 of 54
Computer Science and Engineering Program
Fundamental of the Analysis of Alg.
Efficiency
Gedamu A.
alemugedamu@yahoo.com
Image processing and Computer vision SIG
Some of the sides are exported from different sources to clarify the topic
Computer Science and Engineering Program
Analysis of algorithms
 Issues:
 Correctness
 space efficiency
 time efficiency
 optimality
 Approaches:
 theoretical analysis
 empirical analysis
Computer Science and Engineering Program
Space Analysis
 When considering space complexity, algorithms are divided
into those that need extra space to do their work and those that
work in place.
 Space analysis would examine all of the data being stored to
see if there were more efficient ways to store it.
 Example : As a developer, how do you store the real numbers ?
 Suppose we are storing a real number that has only one place of precision
after the decimal point and ranges between -10 and +10.
 How many bytes you need ?
Computer Science and Engineering Program
Space Analysis
 Example : As a developer, how do you store the real numbers ?
 Suppose we are storing a real number that has only one place of precision
after the decimal point and ranges between -10 and +10.
 How many bytes you need ?
 Most computers will use between 4 and 8 bytes of memory.
 If we first multiply the value by 10. We can then store this as an integer
between -100 and +100. This needs only 1 byte, a savings of 3 to 7 bytes.
 A program that stores 1000 of these values can save 3000 to 7000 bytes.
 It makes a big difference when programming mobile or PDAs or when you
have large input .
Computer Science and Engineering Program
Theoretical analysis of time efficiency
Time efficiency is analyzed by determining the number of repetitions of the
basic operation as a function of input size
 Basic operation: the operation that contributes the most towards the
running time of the algorithm
T(n) ≈ copC(n)
running time execution time
for basic operation
or cost
Number of times
basic operation
is executed
input size
Note: Different basic operations may cost differently!
Computer Science and Engineering Program
Why Input Classes are Important?
 Input determines what the path of execution through an
algorithm will be.
 If we are interested in finding the largest value in a list of N
numbers, we can use the following algorithm:
Computer Science and Engineering Program
Why Input Classes are Important?
 If the list is in decreasing order,
 There will only be one assignment done before the loop starts.
 If the list is in increasing order,
 There will be N assignments (one before the loop starts and N -1 inside the
loop).
 Our analysis must consider more than one possible set of input,
because if we only look at one set of input, it may be the set that is
solved the fastest (or slowest).
Computer Science and Engineering Program
Input size and basic operation examples
Problem Input size measure Basic operation
Searching for key in a list
of n items
Number of list’s items, i.e. n Key comparison
Multiplication of two
matrices
Matrix dimensions or total
number of elements
Multiplication of two
numbers
Checking primality of a
given integer n
n’size = number of digits (in
binary representation)
Division
Typical graph problem #vertices and/or edges
Visiting a vertex or
traversing an edge
Computer Science and Engineering Program
Importance of the analysis
 It gives an idea about how fast the algorithm
 If the number of basic operations
C(n) = ½ n (n-1) = ½ n2 – ½ n ≈ ½ n2
How much longer if the algorithm doubles its input
size?
 Increasing input size increases the complexity
 We tend to omit the constants because they have no effect with large inputs
 Everything is based on estimation
T(n) ≈ copC(n)
4
)(
2
1
)2(
2
1
)(
)2(
2
2
)(
)2(

n
n
nCC
nCC
OP
OP
nT
nT
Computer Science and Engineering Program
Empirical analysis of time efficiency
 Select a specific (typical) sample of inputs
 Use physical unit of time (e.g., milliseconds)
or
Count actual number of basic operation’s executions
 Analyze the empirical/experimental data
Computer Science and Engineering Program
case to consider in analysis
Best-case, average-case, worst-case
For some algorithms, efficiency depends on form of input:
 Worst case: Cworst(n) – maximum over inputs of size n
 Best case: Cbest(n) – minimum over inputs of size n
 Average case: Cavg(n) – “average” over inputs of size n
 The toughest to do
Computer Science and Engineering Program
Best-case, average-case, worst-case
 Average case: Cavg(n) – “average” over inputs of size n
 Determine the number of different groups into which all possible input
sets can be divided.
 Determine the probability that the input will come from each of these
groups.
 Determine how long the algorithm will run for each of these groups.
n is the size of the input,
m is the number of groups,
pi is the probability that the input will be from
group i,
ti is the time that the algorithm takes for input
from group i.
Computer Science and Engineering Program
Example: Sequential search
 Worst case
 Best case
 Average case
n key comparisons
1 comparison
(n+1)/2, assuming K is in A
Computer Science and Engineering Program
Computing the Average Case for the Sequential
search
 Neither the Worst nor the Best case gives the yield to the actual performance of an algorithm
with random input.
 The Average Case does
 Assume that:
 The probability of successful search is equal to p(0≤ p ≤1)
 The probability of the first match occurring in the ith position is the same for every i .
 The probability of a match occurs at ith position is p/n for every i
 In the case of unsuccessful search , the number of comparison is n with probability (1-
p).
)1(
2
)1(
)1.(
2
)1(
.
)1.(]...321[
)1.(]....3.2.1[)(
pn
np
pn
nn
n
p
pnn
n
p
pn
n
p
n
n
p
n
p
n
p
nCavg







Computer Science and Engineering Program
Computing the Average Case for the Sequential
search
 If p =1 (I found the key k)
 The average number of comparisons is (n+1)/2
 If p=0
 The average number of key comparisons is n
 The average Case is more difficult than the Best and Worst cases
)1(
2
)1(
)1.(
2
)1(
.
)1.(]...321[
)1.(]....3.2.1[)(
pn
np
pn
nn
n
p
pnn
n
p
pn
n
p
n
n
p
n
p
n
p
nCavg







Computer Science and Engineering Program
16
Mathematical Background
Computer Science and Engineering Program
Mathematical Background
 Logarithms
Computer Science and Engineering Program
Logarithms
 Which Base ?
Loga n = Loga b Logb n
Loga n = c Logb n
In terms of complexity , we tend to
ignore the constant
Computer Science and Engineering Program
Mathematical Background
Computer Science and Engineering Program
Mathematical Background
Computer Science and Engineering Program
Mathematical Background
 ..
Computer Science and Engineering Program
Types of formulas for basic operation’s count
 Exact formula
e.g., C(n) = n(n-1)/2
 Formula indicating order of growth with specific multiplicative
constant
e.g., C(n) ≈ 0.5 n2
 Formula indicating order of growth with unknown
multiplicative constant
e.g., C(n) ≈ cn2
23
Order of growth
Computer Science and Engineering Program
Order of growth
 Of greater concern is the rate of increase in operations for an
algorithm to solve a problem as the size of the problem
increases.
 This is referred to as the rate of growth of the algorithm.
Computer Science and Engineering Program
Order of growth
 The function based on x2 increases slowly at first, but as the problem size
gets larger, it begins to grow at a rapid rate.
 The functions that are based on x both grow at a steady rate for the entire
length of the graph.
 The function based on log x seems to not grow at all, but this is because it
is actually growing at a very slow rate.
Computer Science and Engineering Program
Values of some important functions as n  
Computer Science and Engineering Program
Order of growth
Second point to consider :
 Because the faster growing functions increase at such a
significant rate, they quickly dominate the slower-growing
functions.
 This means that if we determine that an algorithm’s
complexity is a combination of two of these classes, we will
frequently ignore all but the fastest growing of these terms.
 Example : if the complexity is
we tend to ignore 30x term
Computer Science and Engineering Program
Classification of Growth
Asymptotic order of growth
A way of comparing functions that ignores constant factors and small
input sizes.
 O(g(n)): class of functions f(n) that grow no faster than g(n)
 All functions with smaller or the same order of growth as g(n)
 Ω(g(n)): class of functions f(n) that grow at least as fast as g(n)
 All functions that are larger or have the same order of growth as g(n)
 Θ(g(n)): class of functions f(n) that grow at same rate as g(n)
 Set of functions that have the same order of growth as g(n)
)(),()1(5.0),(5100),( 23222
nOnnOnnnOnnOn 
),(5100),()1(5.0),( 2223
nnnnnnn 
)( 22
nbnan 
Computer Science and Engineering Program
Big-oh
•O(g(n)): class of functions t(n) that grow no faster than g(n)
• if there exist some positive constant c and some nonnegative n0
such that
0)()( nnallforncgnt 
)O(n5100nthatProve:Ex 2

5101
101n101n
5)nall(forn100n5100n
0
2



nandc
You may come up with different c and n0
Computer Science and Engineering Program
Big-omega
Ω(g(n)): class of functions t(n) that grow at least as fast as g(n)
?)(
)()(
23
0
nnthatprove
nnallforncgnt


01
0
0
23


nandc
nallfornn
Computer Science and Engineering Program
Big-theta
Θ(g(n)): class of functions t(n) that grow at same rate as g(n)
02 )(1)()( nnallforngcntngc 
021 ,, nandcc
gettoneedYou
Computer Science and Engineering Program
(g(n)), functions that grow at least as fast as g(n)
(g(n)), functions that grow at the same rate as g(n)
O(g(n)), functions that grow no faster than g(n)
g(n)
>=
<=
=
Summary
Computer Science and Engineering Program
Theorem
 If t1(n)  O(g1(n)) and t2(n)  O(g2(n)), then
t1(n) + t2(n)  O(max{g1(n), g2(n)}).
 The analogous assertions are true for the -notation and -
notation.
 Implication: The algorithm’s overall efficiency will be
determined by the part with a larger order of growth, i.e., its
least efficient part.
 For example, 5n2 + 3nlogn  O(n2)
Proof. There exist constants c1, c2, n1, n2 such that
t1(n)  c1*g1(n), for all n  n1
t2(n)  c2*g2(n), for all n  n2
Define c3 = c1 + c2 and n3 = max{n1,n2}. Then
t1(n) + t2(n)  c3*max{g1(n), g2(n)}, for all n  n3
Computer Science and Engineering Program
Some properties of asymptotic order of growth
 f(n)  O(f(n))
 f(n)  O(g(n)) iff g(n) (f(n))
 If f (n)  O(g (n)) and g(n)  O(h(n)) , then f(n)  O(h(n))
If f1(n)  O(g1(n)) and f2(n)  O(g2(n)) , then
f1(n) + f2(n)  O(max{g1(n), g2(n)})
Also, 1in (f(i)) =  (1in f(i))
Computer Science and Engineering Program
Orders of growth of some important functions
 All logarithmic functions loga n belong to the same class
(log n) no matter what the logarithm’s base a > 1 is
because
 All polynomials of the same degree k belong to the same class:
aknk + ak-1nk-1 + … + a0  (nk)
 Exponential functions an have different orders of growth for
different a’s
ann bba log/loglog 
Computer Science and Engineering Program
Basic asymptotic efficiency classes
1 constant
log n logarithmic
n linear
n log n n-log-n
n2 quadratic
n3 cubic
2n exponential
n! factorial
Computer Science and Engineering Program
Time efficiency of nonrecursive algorithms
General Plan for Analysis
 Decide on parameter n indicating input size
 Identify algorithm’s basic operation
 Determine worst, average, and best cases for input of size n
 Set up a sum for the number of times the basic operation is executed
 Simplify the sum using standard formulas and rules.
Computer Science and Engineering Program
Example 1: The Largest Element
T(n) = 1in-1 (1) = n-1 = (n) comparisons
Computer Science and Engineering Program
Example 2: Element uniqueness problem
T(n) = 0in-2 (i+1jn-1 (1))
= 0in-2 (n-i+1) =
= ( ) comparisons2
n
)(
2
1
2
)1(
1.....)2()1(1
11
22
2
0
nn
nn
nnin
lu
n
i
u
li










Computer Science and Engineering Program
Example 3: Matrix multiplication
T(n) = = ( ) multiplications
Ignored addition for simplicity
3
n  






1
0
1
0
1
0
1
n
i
n
j
n
k
Computer Science and Engineering Program
Example 4: Counting binary digits
It cannot be investigated the way the previous examples are.
The halving game: Find integer i such that n/ ≤ 1.
Answer: i ≤ log n. So, T(n) = (log n) divisions.
Another solution: Using recurrence relations.
i
2
Computer Science and Engineering Program
Plan for Analysis of Recursive Algorithms
 Decide on a parameter indicating an input’s size.
 Identify the algorithm’s basic operation.
 Check whether the number of times the basic op. is executed may
vary on different inputs of the same size. (If it may, the worst,
average, and best cases must be investigated separately.)
 Set up a recurrence relation with an appropriate initial condition
expressing the number of times the basic op. is executed.
 Solve the recurrence (or, at the very least, establish its solution’s
order of growth) by backward substitutions or another method.
Computer Science and Engineering Program
Example 1 : Factorial: Recursive Algorithm
43
The stopping condition is n=0
A repetitive algorithm uses recursion whenever the algorithm
appears within the definition itself.
Computer Science and Engineering Program
Example 1: Recursive evaluation of n!
Definition: n ! = 1  2  … (n-1)  n for n ≥ 1 and 0! = 1
Recursive definition of n!: F(n) = F(n-1)  n for n ≥ 1 and
F(0) = 1
Size:
Basic operation:
Recurrence relation:
n
multiplication
M(n) = M(n-1) (for F(n-1) ) + 1 (for the n * F(n-1))
 M(0) = 0
Computer Science and Engineering Program
Solving the recurrence for M(n)
M(n) = M(n-1) + 1, M(0) = 0 (no multiplication when n=0)
M(n) = M(n-1) + 1
 = (M(n-2) + 1) + 1 = M(n-2) + 2
 = (M(n-3) + 1) + 2 = M(n-3) + 3
 …
 = M(n-i) + i
 = M(0) + n
 = n
The method is called backward substitution.
Computer Science and Engineering Program
Example 2: The Tower of Hanoi Puzzle
46
Towers of Hanoi (aka Tower of Hanoi) is a mathematical puzzle
invented by a French Mathematician Edouard Lucas in 1983.
•Initially the game has few discs arranged in the increasing
order of size in one of the tower.
• The number of discs can vary, but there are only three towers.
•The goal is to transfer the discs from one tower another tower.
However you can move only one disk at a time and you can
never place a bigger disc over a smaller disk. It is also
understood that you can only take the top most disc from any
given tower.
Computer Science and Engineering Program
Example 2: The Tower of Hanoi Puzzle
Recurrence for number of moves: M(n) = 2M(n-1) + 1
Computer Science and Engineering Program
1
2
3
4
5
6
7
0 Move Sequence for d = 3
Computer Science and Engineering Program
The Tower of Hanoi Puzzle
 Here's how to find the number of moves needed to transfer larger
numbers of disks from post A to post C, when M = the number of
moves needed to transfer n-1 disks from post A to post C:
 for 1 disk it takes 1 move to transfer 1 disk from post A to post C;
 for 2 disks, it will take 3 moves: 2M + 1 = 2(1) + 1 = 3
 for 3 disks, it will take 7 moves: 2M + 1 = 2(3) + 1 = 7
 for 4 disks, it will take 15 moves: 2M + 1 = 2(7) + 1 = 15
 for 5 disks, it will take 31 moves: 2M + 1 = 2(15) + 1 = 31
 for 6 disks... ?
Computer Science and Engineering Program
Explicit Pattern
 Number of Disks Number of Moves
1 1
2 3
3 7
4 15
5 31
6 63
Computer Science and Engineering Program
Powers of two help reveal the pattern:
 Number of Disks (n) Number of Moves
1 21 - 1 = 2 - 1 = 1
2 22 - 1 = 4 - 1 = 3
3 23 - 1 = 8 - 1 = 7
4 24 - 1 = 16 - 1 = 15
5 25 - 1 = 32 - 1 = 31
6 26 - 1 = 64 - 1 = 63
Computer Science and Engineering Program
Fascinating fact
So the formula for finding the number of steps it takes to transfer
n disks from post A to post C is:
2
n - 1
Computer Science and Engineering Program
Solving recurrence for number of moves
M(n) = 2M(n-1) + 1, M(1) = 1
M(n) = 2M(n-1) + 1
= 2(2M(n-2) + 1) + 1 = 2^2*M(n-2) + 2^1 + 2^0
= 2^2*(2M(n-3) + 1) + 2^1 + 2^0
= 2^3*M(n-3) + 2^2 + 2^1 + 2^0
= …
= 2^(n-1)*M(1) + 2^(n-2) + … + 2^1 + 2^0
= 2^(n-1) + 2^(n-2) + … + 2^1 + 2^0
= 2^n - 1
Computer Science and Engineering Program
Fibonacci Sequence
 The Fibonacci numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, …
 The Fibonacci recurrence:
F(n) = F(n-1) + F(n-2)
F(0) = 0
F(1) = 1
 F(n) = F(n-1) + F(n-2) or F(n) - F(n-1) - F(n-2) = 0
General 2nd order linear homogeneous recurrence with
constant coefficients:
aX(n) + bX(n-1) + cX(n-2) = 0
What Is the
Important of
Fibonacci
Sequence?

More Related Content

What's hot

Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2chidabdu
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMSTanya Makkar
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IMohamed Loey
 
Design and analysis of Algorithm By Dr. B. J. Mohite
Design and analysis of Algorithm By Dr. B. J. MohiteDesign and analysis of Algorithm By Dr. B. J. Mohite
Design and analysis of Algorithm By Dr. B. J. MohiteZeal Education Society, Pune
 
Mathematical Analysis of Non-Recursive Algorithm.
Mathematical Analysis of Non-Recursive Algorithm.Mathematical Analysis of Non-Recursive Algorithm.
Mathematical Analysis of Non-Recursive Algorithm.mohanrathod18
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.Tariq Khan
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Dr. Pankaj Agarwal
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)swapnac12
 
Unit i basic concepts of algorithms
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithmssangeetha s
 
Big o notation
Big o notationBig o notation
Big o notationkeb97
 
Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Muhammad Hammad Waseem
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to AlgorithmsVenkatesh Iyer
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Deepak John
 
Analysis and design of algorithms part2
Analysis and design of algorithms part2Analysis and design of algorithms part2
Analysis and design of algorithms part2Deepak John
 
CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsKrishnan MuthuManickam
 

What's hot (20)

Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Design and analysis of Algorithm By Dr. B. J. Mohite
Design and analysis of Algorithm By Dr. B. J. MohiteDesign and analysis of Algorithm By Dr. B. J. Mohite
Design and analysis of Algorithm By Dr. B. J. Mohite
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Slide2
Slide2Slide2
Slide2
 
Mathematical Analysis of Non-Recursive Algorithm.
Mathematical Analysis of Non-Recursive Algorithm.Mathematical Analysis of Non-Recursive Algorithm.
Mathematical Analysis of Non-Recursive Algorithm.
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 
Unit i basic concepts of algorithms
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithms
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
Big o notation
Big o notationBig o notation
Big o notation
 
Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
Analysis and design of algorithms part2
Analysis and design of algorithms part2Analysis and design of algorithms part2
Analysis and design of algorithms part2
 
CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of Algorithms
 

Viewers also liked

Página 35 fat tony e cockburn
Página 35   fat tony e cockburnPágina 35   fat tony e cockburn
Página 35 fat tony e cockburnAbs Pecplan
 
257_azterketa popsterra konpis.pdf
257_azterketa popsterra konpis.pdf257_azterketa popsterra konpis.pdf
257_azterketa popsterra konpis.pdfElhuyarOlinpiada
 
Presentation1
Presentation1Presentation1
Presentation1bedncal17
 
Conorgallaghermomentumassessed
ConorgallaghermomentumassessedConorgallaghermomentumassessed
ConorgallaghermomentumassessedconorRG
 
Seven first days in the Bible
Seven first days in the BibleSeven first days in the Bible
Seven first days in the BibleDavid Rayi
 
Instrukacja montazu-drzwi-ozdobnych-orac
Instrukacja montazu-drzwi-ozdobnych-oracInstrukacja montazu-drzwi-ozdobnych-orac
Instrukacja montazu-drzwi-ozdobnych-oracskleporac
 
Introduzione al web marketing
Introduzione al web marketingIntroduzione al web marketing
Introduzione al web marketingragazzosolo
 
1097_ikusmena engainatzen.doc
1097_ikusmena engainatzen.doc1097_ikusmena engainatzen.doc
1097_ikusmena engainatzen.docElhuyarOlinpiada
 
Redes Sociais Para Pequenas Empresas
Redes Sociais Para Pequenas EmpresasRedes Sociais Para Pequenas Empresas
Redes Sociais Para Pequenas EmpresasKelli Lima
 
Aliran filsafat-1213708448970181-9
Aliran filsafat-1213708448970181-9Aliran filsafat-1213708448970181-9
Aliran filsafat-1213708448970181-9inayahnia
 
Deures tecno metnoferric_estiu2010
Deures tecno metnoferric_estiu2010Deures tecno metnoferric_estiu2010
Deures tecno metnoferric_estiu2010Escola Cervetó
 
El senyor cornèlius és un bon mataroní[1]
El senyor cornèlius és un bon mataroní[1]El senyor cornèlius és un bon mataroní[1]
El senyor cornèlius és un bon mataroní[1]Cpstdseso
 

Viewers also liked (20)

Página 35 fat tony e cockburn
Página 35   fat tony e cockburnPágina 35   fat tony e cockburn
Página 35 fat tony e cockburn
 
zuuka.pdf
zuuka.pdfzuuka.pdf
zuuka.pdf
 
Cisco EEM Techsheet
Cisco EEM TechsheetCisco EEM Techsheet
Cisco EEM Techsheet
 
257_azterketa popsterra konpis.pdf
257_azterketa popsterra konpis.pdf257_azterketa popsterra konpis.pdf
257_azterketa popsterra konpis.pdf
 
Presentation1
Presentation1Presentation1
Presentation1
 
Conorgallaghermomentumassessed
ConorgallaghermomentumassessedConorgallaghermomentumassessed
Conorgallaghermomentumassessed
 
Seven first days in the Bible
Seven first days in the BibleSeven first days in the Bible
Seven first days in the Bible
 
Biuletyn
BiuletynBiuletyn
Biuletyn
 
Kharb
KharbKharb
Kharb
 
Instrukacja montazu-drzwi-ozdobnych-orac
Instrukacja montazu-drzwi-ozdobnych-oracInstrukacja montazu-drzwi-ozdobnych-orac
Instrukacja montazu-drzwi-ozdobnych-orac
 
Moodboard (makeup)
Moodboard (makeup)Moodboard (makeup)
Moodboard (makeup)
 
Introduzione al web marketing
Introduzione al web marketingIntroduzione al web marketing
Introduzione al web marketing
 
1097_ikusmena engainatzen.doc
1097_ikusmena engainatzen.doc1097_ikusmena engainatzen.doc
1097_ikusmena engainatzen.doc
 
Composite
CompositeComposite
Composite
 
Resumen nov.
Resumen nov.Resumen nov.
Resumen nov.
 
Redes Sociais Para Pequenas Empresas
Redes Sociais Para Pequenas EmpresasRedes Sociais Para Pequenas Empresas
Redes Sociais Para Pequenas Empresas
 
Aliran filsafat-1213708448970181-9
Aliran filsafat-1213708448970181-9Aliran filsafat-1213708448970181-9
Aliran filsafat-1213708448970181-9
 
Deures tecno metnoferric_estiu2010
Deures tecno metnoferric_estiu2010Deures tecno metnoferric_estiu2010
Deures tecno metnoferric_estiu2010
 
5to
5to5to
5to
 
El senyor cornèlius és un bon mataroní[1]
El senyor cornèlius és un bon mataroní[1]El senyor cornèlius és un bon mataroní[1]
El senyor cornèlius és un bon mataroní[1]
 

Similar to Chapter two

Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdfMemMem25
 
lecture 1
lecture 1lecture 1
lecture 1sajinsc
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusNANDINI SHARMA
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsAbdullah Al-hazmy
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...TechVision8
 
Data Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm AnalysisData Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm AnalysisFerdin Joe John Joseph PhD
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptxNishaS88
 
Data Structure & Algorithms - Introduction
Data Structure & Algorithms - IntroductionData Structure & Algorithms - Introduction
Data Structure & Algorithms - Introductionbabuk110
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...AntareepMajumder
 

Similar to Chapter two (20)

Algorithms
Algorithms Algorithms
Algorithms
 
Big Oh.ppt
Big Oh.pptBig Oh.ppt
Big Oh.ppt
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 
lecture 1
lecture 1lecture 1
lecture 1
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
 
Data Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm AnalysisData Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm Analysis
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Lec1
Lec1Lec1
Lec1
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
 
Data Structure & Algorithms - Introduction
Data Structure & Algorithms - IntroductionData Structure & Algorithms - Introduction
Data Structure & Algorithms - Introduction
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
 
Chapter one
Chapter oneChapter one
Chapter one
 
Annotations.pdf
Annotations.pdfAnnotations.pdf
Annotations.pdf
 
Analysis algorithm
Analysis algorithmAnalysis algorithm
Analysis algorithm
 

Recently uploaded

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 

Recently uploaded (20)

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 

Chapter two

  • 1. Computer Science and Engineering Program Fundamental of the Analysis of Alg. Efficiency Gedamu A. alemugedamu@yahoo.com Image processing and Computer vision SIG Some of the sides are exported from different sources to clarify the topic
  • 2. Computer Science and Engineering Program Analysis of algorithms  Issues:  Correctness  space efficiency  time efficiency  optimality  Approaches:  theoretical analysis  empirical analysis
  • 3. Computer Science and Engineering Program Space Analysis  When considering space complexity, algorithms are divided into those that need extra space to do their work and those that work in place.  Space analysis would examine all of the data being stored to see if there were more efficient ways to store it.  Example : As a developer, how do you store the real numbers ?  Suppose we are storing a real number that has only one place of precision after the decimal point and ranges between -10 and +10.  How many bytes you need ?
  • 4. Computer Science and Engineering Program Space Analysis  Example : As a developer, how do you store the real numbers ?  Suppose we are storing a real number that has only one place of precision after the decimal point and ranges between -10 and +10.  How many bytes you need ?  Most computers will use between 4 and 8 bytes of memory.  If we first multiply the value by 10. We can then store this as an integer between -100 and +100. This needs only 1 byte, a savings of 3 to 7 bytes.  A program that stores 1000 of these values can save 3000 to 7000 bytes.  It makes a big difference when programming mobile or PDAs or when you have large input .
  • 5. Computer Science and Engineering Program Theoretical analysis of time efficiency Time efficiency is analyzed by determining the number of repetitions of the basic operation as a function of input size  Basic operation: the operation that contributes the most towards the running time of the algorithm T(n) ≈ copC(n) running time execution time for basic operation or cost Number of times basic operation is executed input size Note: Different basic operations may cost differently!
  • 6. Computer Science and Engineering Program Why Input Classes are Important?  Input determines what the path of execution through an algorithm will be.  If we are interested in finding the largest value in a list of N numbers, we can use the following algorithm:
  • 7. Computer Science and Engineering Program Why Input Classes are Important?  If the list is in decreasing order,  There will only be one assignment done before the loop starts.  If the list is in increasing order,  There will be N assignments (one before the loop starts and N -1 inside the loop).  Our analysis must consider more than one possible set of input, because if we only look at one set of input, it may be the set that is solved the fastest (or slowest).
  • 8. Computer Science and Engineering Program Input size and basic operation examples Problem Input size measure Basic operation Searching for key in a list of n items Number of list’s items, i.e. n Key comparison Multiplication of two matrices Matrix dimensions or total number of elements Multiplication of two numbers Checking primality of a given integer n n’size = number of digits (in binary representation) Division Typical graph problem #vertices and/or edges Visiting a vertex or traversing an edge
  • 9. Computer Science and Engineering Program Importance of the analysis  It gives an idea about how fast the algorithm  If the number of basic operations C(n) = ½ n (n-1) = ½ n2 – ½ n ≈ ½ n2 How much longer if the algorithm doubles its input size?  Increasing input size increases the complexity  We tend to omit the constants because they have no effect with large inputs  Everything is based on estimation T(n) ≈ copC(n) 4 )( 2 1 )2( 2 1 )( )2( 2 2 )( )2(  n n nCC nCC OP OP nT nT
  • 10. Computer Science and Engineering Program Empirical analysis of time efficiency  Select a specific (typical) sample of inputs  Use physical unit of time (e.g., milliseconds) or Count actual number of basic operation’s executions  Analyze the empirical/experimental data
  • 11. Computer Science and Engineering Program case to consider in analysis Best-case, average-case, worst-case For some algorithms, efficiency depends on form of input:  Worst case: Cworst(n) – maximum over inputs of size n  Best case: Cbest(n) – minimum over inputs of size n  Average case: Cavg(n) – “average” over inputs of size n  The toughest to do
  • 12. Computer Science and Engineering Program Best-case, average-case, worst-case  Average case: Cavg(n) – “average” over inputs of size n  Determine the number of different groups into which all possible input sets can be divided.  Determine the probability that the input will come from each of these groups.  Determine how long the algorithm will run for each of these groups. n is the size of the input, m is the number of groups, pi is the probability that the input will be from group i, ti is the time that the algorithm takes for input from group i.
  • 13. Computer Science and Engineering Program Example: Sequential search  Worst case  Best case  Average case n key comparisons 1 comparison (n+1)/2, assuming K is in A
  • 14. Computer Science and Engineering Program Computing the Average Case for the Sequential search  Neither the Worst nor the Best case gives the yield to the actual performance of an algorithm with random input.  The Average Case does  Assume that:  The probability of successful search is equal to p(0≤ p ≤1)  The probability of the first match occurring in the ith position is the same for every i .  The probability of a match occurs at ith position is p/n for every i  In the case of unsuccessful search , the number of comparison is n with probability (1- p). )1( 2 )1( )1.( 2 )1( . )1.(]...321[ )1.(]....3.2.1[)( pn np pn nn n p pnn n p pn n p n n p n p n p nCavg       
  • 15. Computer Science and Engineering Program Computing the Average Case for the Sequential search  If p =1 (I found the key k)  The average number of comparisons is (n+1)/2  If p=0  The average number of key comparisons is n  The average Case is more difficult than the Best and Worst cases )1( 2 )1( )1.( 2 )1( . )1.(]...321[ )1.(]....3.2.1[)( pn np pn nn n p pnn n p pn n p n n p n p n p nCavg       
  • 16. Computer Science and Engineering Program 16 Mathematical Background
  • 17. Computer Science and Engineering Program Mathematical Background  Logarithms
  • 18. Computer Science and Engineering Program Logarithms  Which Base ? Loga n = Loga b Logb n Loga n = c Logb n In terms of complexity , we tend to ignore the constant
  • 19. Computer Science and Engineering Program Mathematical Background
  • 20. Computer Science and Engineering Program Mathematical Background
  • 21. Computer Science and Engineering Program Mathematical Background  ..
  • 22. Computer Science and Engineering Program Types of formulas for basic operation’s count  Exact formula e.g., C(n) = n(n-1)/2  Formula indicating order of growth with specific multiplicative constant e.g., C(n) ≈ 0.5 n2  Formula indicating order of growth with unknown multiplicative constant e.g., C(n) ≈ cn2
  • 24. Computer Science and Engineering Program Order of growth  Of greater concern is the rate of increase in operations for an algorithm to solve a problem as the size of the problem increases.  This is referred to as the rate of growth of the algorithm.
  • 25. Computer Science and Engineering Program Order of growth  The function based on x2 increases slowly at first, but as the problem size gets larger, it begins to grow at a rapid rate.  The functions that are based on x both grow at a steady rate for the entire length of the graph.  The function based on log x seems to not grow at all, but this is because it is actually growing at a very slow rate.
  • 26. Computer Science and Engineering Program Values of some important functions as n  
  • 27. Computer Science and Engineering Program Order of growth Second point to consider :  Because the faster growing functions increase at such a significant rate, they quickly dominate the slower-growing functions.  This means that if we determine that an algorithm’s complexity is a combination of two of these classes, we will frequently ignore all but the fastest growing of these terms.  Example : if the complexity is we tend to ignore 30x term
  • 28. Computer Science and Engineering Program Classification of Growth Asymptotic order of growth A way of comparing functions that ignores constant factors and small input sizes.  O(g(n)): class of functions f(n) that grow no faster than g(n)  All functions with smaller or the same order of growth as g(n)  Ω(g(n)): class of functions f(n) that grow at least as fast as g(n)  All functions that are larger or have the same order of growth as g(n)  Θ(g(n)): class of functions f(n) that grow at same rate as g(n)  Set of functions that have the same order of growth as g(n) )(),()1(5.0),(5100),( 23222 nOnnOnnnOnnOn  ),(5100),()1(5.0),( 2223 nnnnnnn  )( 22 nbnan 
  • 29. Computer Science and Engineering Program Big-oh •O(g(n)): class of functions t(n) that grow no faster than g(n) • if there exist some positive constant c and some nonnegative n0 such that 0)()( nnallforncgnt  )O(n5100nthatProve:Ex 2  5101 101n101n 5)nall(forn100n5100n 0 2    nandc You may come up with different c and n0
  • 30. Computer Science and Engineering Program Big-omega Ω(g(n)): class of functions t(n) that grow at least as fast as g(n) ?)( )()( 23 0 nnthatprove nnallforncgnt   01 0 0 23   nandc nallfornn
  • 31. Computer Science and Engineering Program Big-theta Θ(g(n)): class of functions t(n) that grow at same rate as g(n) 02 )(1)()( nnallforngcntngc  021 ,, nandcc gettoneedYou
  • 32. Computer Science and Engineering Program (g(n)), functions that grow at least as fast as g(n) (g(n)), functions that grow at the same rate as g(n) O(g(n)), functions that grow no faster than g(n) g(n) >= <= = Summary
  • 33. Computer Science and Engineering Program Theorem  If t1(n)  O(g1(n)) and t2(n)  O(g2(n)), then t1(n) + t2(n)  O(max{g1(n), g2(n)}).  The analogous assertions are true for the -notation and - notation.  Implication: The algorithm’s overall efficiency will be determined by the part with a larger order of growth, i.e., its least efficient part.  For example, 5n2 + 3nlogn  O(n2) Proof. There exist constants c1, c2, n1, n2 such that t1(n)  c1*g1(n), for all n  n1 t2(n)  c2*g2(n), for all n  n2 Define c3 = c1 + c2 and n3 = max{n1,n2}. Then t1(n) + t2(n)  c3*max{g1(n), g2(n)}, for all n  n3
  • 34. Computer Science and Engineering Program Some properties of asymptotic order of growth  f(n)  O(f(n))  f(n)  O(g(n)) iff g(n) (f(n))  If f (n)  O(g (n)) and g(n)  O(h(n)) , then f(n)  O(h(n)) If f1(n)  O(g1(n)) and f2(n)  O(g2(n)) , then f1(n) + f2(n)  O(max{g1(n), g2(n)}) Also, 1in (f(i)) =  (1in f(i))
  • 35. Computer Science and Engineering Program Orders of growth of some important functions  All logarithmic functions loga n belong to the same class (log n) no matter what the logarithm’s base a > 1 is because  All polynomials of the same degree k belong to the same class: aknk + ak-1nk-1 + … + a0  (nk)  Exponential functions an have different orders of growth for different a’s ann bba log/loglog 
  • 36. Computer Science and Engineering Program Basic asymptotic efficiency classes 1 constant log n logarithmic n linear n log n n-log-n n2 quadratic n3 cubic 2n exponential n! factorial
  • 37. Computer Science and Engineering Program Time efficiency of nonrecursive algorithms General Plan for Analysis  Decide on parameter n indicating input size  Identify algorithm’s basic operation  Determine worst, average, and best cases for input of size n  Set up a sum for the number of times the basic operation is executed  Simplify the sum using standard formulas and rules.
  • 38. Computer Science and Engineering Program Example 1: The Largest Element T(n) = 1in-1 (1) = n-1 = (n) comparisons
  • 39. Computer Science and Engineering Program Example 2: Element uniqueness problem T(n) = 0in-2 (i+1jn-1 (1)) = 0in-2 (n-i+1) = = ( ) comparisons2 n )( 2 1 2 )1( 1.....)2()1(1 11 22 2 0 nn nn nnin lu n i u li          
  • 40. Computer Science and Engineering Program Example 3: Matrix multiplication T(n) = = ( ) multiplications Ignored addition for simplicity 3 n         1 0 1 0 1 0 1 n i n j n k
  • 41. Computer Science and Engineering Program Example 4: Counting binary digits It cannot be investigated the way the previous examples are. The halving game: Find integer i such that n/ ≤ 1. Answer: i ≤ log n. So, T(n) = (log n) divisions. Another solution: Using recurrence relations. i 2
  • 42. Computer Science and Engineering Program Plan for Analysis of Recursive Algorithms  Decide on a parameter indicating an input’s size.  Identify the algorithm’s basic operation.  Check whether the number of times the basic op. is executed may vary on different inputs of the same size. (If it may, the worst, average, and best cases must be investigated separately.)  Set up a recurrence relation with an appropriate initial condition expressing the number of times the basic op. is executed.  Solve the recurrence (or, at the very least, establish its solution’s order of growth) by backward substitutions or another method.
  • 43. Computer Science and Engineering Program Example 1 : Factorial: Recursive Algorithm 43 The stopping condition is n=0 A repetitive algorithm uses recursion whenever the algorithm appears within the definition itself.
  • 44. Computer Science and Engineering Program Example 1: Recursive evaluation of n! Definition: n ! = 1  2  … (n-1)  n for n ≥ 1 and 0! = 1 Recursive definition of n!: F(n) = F(n-1)  n for n ≥ 1 and F(0) = 1 Size: Basic operation: Recurrence relation: n multiplication M(n) = M(n-1) (for F(n-1) ) + 1 (for the n * F(n-1))  M(0) = 0
  • 45. Computer Science and Engineering Program Solving the recurrence for M(n) M(n) = M(n-1) + 1, M(0) = 0 (no multiplication when n=0) M(n) = M(n-1) + 1  = (M(n-2) + 1) + 1 = M(n-2) + 2  = (M(n-3) + 1) + 2 = M(n-3) + 3  …  = M(n-i) + i  = M(0) + n  = n The method is called backward substitution.
  • 46. Computer Science and Engineering Program Example 2: The Tower of Hanoi Puzzle 46 Towers of Hanoi (aka Tower of Hanoi) is a mathematical puzzle invented by a French Mathematician Edouard Lucas in 1983. •Initially the game has few discs arranged in the increasing order of size in one of the tower. • The number of discs can vary, but there are only three towers. •The goal is to transfer the discs from one tower another tower. However you can move only one disk at a time and you can never place a bigger disc over a smaller disk. It is also understood that you can only take the top most disc from any given tower.
  • 47. Computer Science and Engineering Program Example 2: The Tower of Hanoi Puzzle Recurrence for number of moves: M(n) = 2M(n-1) + 1
  • 48. Computer Science and Engineering Program 1 2 3 4 5 6 7 0 Move Sequence for d = 3
  • 49. Computer Science and Engineering Program The Tower of Hanoi Puzzle  Here's how to find the number of moves needed to transfer larger numbers of disks from post A to post C, when M = the number of moves needed to transfer n-1 disks from post A to post C:  for 1 disk it takes 1 move to transfer 1 disk from post A to post C;  for 2 disks, it will take 3 moves: 2M + 1 = 2(1) + 1 = 3  for 3 disks, it will take 7 moves: 2M + 1 = 2(3) + 1 = 7  for 4 disks, it will take 15 moves: 2M + 1 = 2(7) + 1 = 15  for 5 disks, it will take 31 moves: 2M + 1 = 2(15) + 1 = 31  for 6 disks... ?
  • 50. Computer Science and Engineering Program Explicit Pattern  Number of Disks Number of Moves 1 1 2 3 3 7 4 15 5 31 6 63
  • 51. Computer Science and Engineering Program Powers of two help reveal the pattern:  Number of Disks (n) Number of Moves 1 21 - 1 = 2 - 1 = 1 2 22 - 1 = 4 - 1 = 3 3 23 - 1 = 8 - 1 = 7 4 24 - 1 = 16 - 1 = 15 5 25 - 1 = 32 - 1 = 31 6 26 - 1 = 64 - 1 = 63
  • 52. Computer Science and Engineering Program Fascinating fact So the formula for finding the number of steps it takes to transfer n disks from post A to post C is: 2 n - 1
  • 53. Computer Science and Engineering Program Solving recurrence for number of moves M(n) = 2M(n-1) + 1, M(1) = 1 M(n) = 2M(n-1) + 1 = 2(2M(n-2) + 1) + 1 = 2^2*M(n-2) + 2^1 + 2^0 = 2^2*(2M(n-3) + 1) + 2^1 + 2^0 = 2^3*M(n-3) + 2^2 + 2^1 + 2^0 = … = 2^(n-1)*M(1) + 2^(n-2) + … + 2^1 + 2^0 = 2^(n-1) + 2^(n-2) + … + 2^1 + 2^0 = 2^n - 1
  • 54. Computer Science and Engineering Program Fibonacci Sequence  The Fibonacci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, …  The Fibonacci recurrence: F(n) = F(n-1) + F(n-2) F(0) = 0 F(1) = 1  F(n) = F(n-1) + F(n-2) or F(n) - F(n-1) - F(n-2) = 0 General 2nd order linear homogeneous recurrence with constant coefficients: aX(n) + bX(n-1) + cX(n-2) = 0 What Is the Important of Fibonacci Sequence?