Computational Complexity: Data Structure and Algorithms
Computational Complexity: Data Structure and Algorithms
Computational Complexity
Analysis of Algorithms
Time complexity
Experimental Analysis
Big-O Analysis
Space complexity
2 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
What is the COST of an algorithm? www.foxitsoftware.com/shopping
3 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Time Complexity www.foxitsoftware.com/shopping
4 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Experimental Analysis www.foxitsoftware.com/shopping
5 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Experimental Analysis www.foxitsoftware.com/shopping
Problems:
An algorithm must be fully implemented to study its running time
Results will vary depending upon hardware of machine, CPU, Memory
Even same system can take different time for same input, as CPU is shared with other processes.
Running times of two algorithms are difficult to directly compare unless the
experiments are performed in the same hardware and software environments.
One program may be better implemented than the other
Experiments can be done only on a limited set of test inputs; hence, they leave out the
running times of inputs not included in the experiment (and these inputs may be
important).
A Better Approach?
Count the steps rather then time
6 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Time Complexity Analysis www.foxitsoftware.com/shopping
7 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Time Complexity Analysis www.foxitsoftware.com/shopping
8 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Calculating T(n) www.foxitsoftware.com/shopping
To estimate T(n), we simply need to know the total number of steps it takes to
complete.
sum= 0
1.
2. For i = 0 to n-1
3. sum+= i
4. i=i+1
5. End For
6. print sum
T(n)=3n+4
How we counted the steps?
How many operations are performed?
assignment, condition, return
9 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Single Loop www.foxitsoftware.com/shopping
1. sum= 0
1 assignment step
2. For i = 1 to n 1 assignment step i=1
n+1 conditional step
3. sum+= i (i.e. i<n
4. i=i+1
n addition steps
5. End For
n increment step
6. print sum
1 print step
T(n)=3n+4
10 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Nested Loops www.foxitsoftware.com/shopping
1 step
T(n,k)= 3nk+3n+4
The total number of times a statement inside inner loop executes = outer loop times * inner loop times
11 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Time Complexity Analysis www.foxitsoftware.com/shopping
T(n) can vary for different scenarios for same value of n, there can be three cases:
Worst case
Maximum number of steps an algorithm
takes on any input of size n.
Best case
Minimum number of steps an algorithm
takes on any input of size n.
Average case
Average number of steps an algorithm
takes on any input of size n.
Worst-case analysis is much easier than average-case analysis, as it requires only the ability to
identify the worst-case input, which is often simple
12 06/10/2015
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Growth Order? www.foxitsoftware.com/shopping
Asymptotic complexity studies the efficiency of an algorithm as the input size becomes large
13 06/10/2015
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Growth Order? www.foxitsoftware.com/shopping
14 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Growth Order? www.foxitsoftware.com/shopping
15 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Asymptotic Analysis www.foxitsoftware.com/shopping
16 06/10/2015
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Big-O Rules www.foxitsoftware.com/shopping
19 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Major Growth Orders www.foxitsoftware.com/shopping
The big-O notation gives an upper bound on the growth rate of a function
We can use the big-O notation to rank functions according to their growth rate.
Seven functions are ordered by increasing growth rate in the sequence below, that is, if
a function f (n) precedes a function g(n) in the sequence, then f(n) is O(g(n)):
20 15-Oct-2020
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Growth Rate Comparison www.foxitsoftware.com/shopping
21 06/10/2015
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
Summary www.foxitsoftware.com/shopping
31 15-Oct-2020