Asymptotic Analysis in Data Structures and Analysis
RachanaMehta11
18 views
26 slides
Aug 20, 2024
Slide 1 of 26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
About This Presentation
Asymptotic Analysis
Size: 586.14 KB
Language: en
Added: Aug 20, 2024
Slides: 26 pages
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}
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;