Asymptotic Analysis in Data Structures and Analysis

RachanaMehta11 18 views 26 slides Aug 20, 2024
Slide 1
Slide 1 of 26
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26

About This Presentation

Asymptotic Analysis


Slide Content

Asymptotic Analysis Rachana Mehta

Algorithmic Analysis Why the algorithmic analysis is necessary ?

Algorithmic Analysis Why the algorithmic analysis is necessary ? Efficient : Less Running Time Less Memory Used Efficiency of a Algorithm/Function based on the amount of input

Algorithmic Analysis Why the algorithmic analysis is necessary ? Efficient : Less Running Time : Time Complexity Less Memory Used : Space Complexity Efficiency of a Algorithm/Function based on the amount of input

How can we measure the running time of a algorithm ? Execution ? Is it a good choice ?

Measuring the Running Time with a Pseudo-Code Generalize language/flow/stepwise instructions for implementing a algorithm/function Primitive Operation : Low level Operations : Data Assignment Control Statements (break,continue, function call,return) Arithmetic or Logical Operation

Measuring the Running Time with a Pseudo-Code Generalize language/flow/stepwise instructions for implementing a algorithm/function Programming Constructs: for loop, while loop, do-while loop if-else statement

Asymptotic Notation Asymptotic notations are the mathematical notations used to describe the running time of an algorithm Three Main Asymptotic Notation : Big-O Notation Omega Notation Theta Notation

Asymptotic Notation Big-O Notation : Upper Bound : Worst Case Analysis A Function f(n) belongs to the set O(g(n)), if there exist a positive constant c such that f(n) lies between 0 and c*g(n), for sufficiently large n. O(g(n)) = { f(n): there exist positive constants c and n0 such that 0 ≤ f(n) ≤ cg(n) for all n ≥ n0 }

Asymptotic Notation Omega Notation : Lower Bound : Best Case Analysis A Function f(n) belongs to the set Ω(g(n)), if there exist a positive constant c such that f(n) lies above c*g(n), for sufficiently large n. Ω(g(n)) = { f(n): there exist positive constants c and n0 such that 0 ≤ cg(n) ≤ f(n) for all n ≥ n0 }

Asymptotic Notation Theta Notation : Average Case Analysis A Function f(n) belongs to the set ϴ(g(n)), if there exist a positive constant c 1 and c 2 such that f(n) lies between c 1 *g(n) and c 2 *g(n), for sufficiently large n. Θ (g(n)) = {f(n): there exist positive constants c1, c2 and n0 such that 0 ≤ c1 * g(n) ≤ f(n) ≤ c2 * g(n) for all n ≥ n0}

Rules for Order Arithmetic : Multiplicative Constants O(k * f(n)) = O(f(n)) Addition Rule O(f(n) + g(n)) = max(f(n), g(n)) Multiplication Rule O(f(n) * g(n)) = O(f(n)) * O(g(n)) Examples: O(1000n) = O(n) O(n 2 + 3n + 2) = O(n 2 ) O(3n 3 + 6n 2 - 4n + 2) = O(3n 3 ) = O(n 3 ) If f(x) = n 2 * log n = O(n 2 logn)

Asymptotic Growth Table

Examples for (i = 0; i < n; i++) cin>>A[i];

Examples for (i = 0; i < n; i++) for (j = 0; j < n; j++) cin >> A[i][j];

Examples for (i = 0; i < n; i++) for (j = 0; j < i; j++) cin >> A[i][j];

Examples for (i = 0; i < n; i++) cin>>B[i]; for (i = 0; i < n; i++) for (j = 0; j < i; j++) cin >> A[i][j];

Examples for (i = 0; i < n; i++) for (k = 0;k < n; k++) cin>>B[k]; for (j = 0; j < 2*n; j++) cin >> “Hello”; cin >> A[j];

Examples for (i = 0; i < n; i++) for (k = 0;k < n; k++) cin>>B[k]; for (m = 0; m < n; m++) for (j = 0; j < 2*n; j++) cin >> “Hello”; cin >> A[j];

Examples int i = 0; int A[100]; int n =100; Take a number for “rollno” from user while(( A[i] != rollno) && (i<n)) i++; if (i > n) cout << "not found"; else cout << "found";

Examples int i = n; while( i>=1) x = x+1 ; i = i/2;

Insertion Sort - Sample

Insertion Sort - Algorithm

Insertion Sort

Insertion Sort

Insertion Sort
Tags