computational complexity
TRANSCRIPT
![Page 2: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/2.jpg)
Background• The running time of a program is proportional to some
constant multiplied by one of these terms plus some smaller terms
Leading Term + Smaller Terms (Negligible for larger N)
![Page 3: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/3.jpg)
Examples• N3 + 5 * N2 – 3 * N + 7
N3 is the leading term
• N = 108
3 * N2 and 2 * N3
Constant coefficients can be ignored
![Page 4: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/4.jpg)
Computational Complexity• Here the worst case performance of algorithms is studied• Constant factors are ignored• Determine the functional dependence of the running time
![Page 5: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/5.jpg)
Definition of Big-Oh Notation• A function g(N) is said to O(f(N)) if there exists constants c0
and N0 such that g(N) is less than c0 * f (N) for all N > N0
![Page 6: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/6.jpg)
Examples• 7 * N - 2
7 *N – 2 is O (N)
Take c0 = 7, N0 = 1
• 3 * N3 + 20 * N2 + 5
3 * N3 + 20 * N2 + 5 is O (N3)
Take c0 = 4, N0 = 21
• 3 * log N + 5
3 * log N +5 is O (log N)
Take c0 = 11, N0 = 2
![Page 7: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/7.jpg)
Problem• 7 * N – 2 < N2
Take c0 = 7, N0 = 1
?
![Page 8: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/8.jpg)
Growth Rate• Functions in order of increasing growth rate is as follows
1 log N N N log N N2
N3
2N
![Page 9: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/9.jpg)
Examples of Algorithm Running Times• Min element of an array: O (N)• Closest points in the plane,
i.e. smallest distance pairs: N (N - 1)/2 O (N2)
![Page 10: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/10.jpg)
Comparing Algorithms Experimentally• Implement each algorithm
– Lots of work– Error prone
• Run it with sample data• Count the time
– Same hardware and software are used
![Page 11: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/11.jpg)
A Sample C Programvoid main ()
{
clrscr ();
clock_t start, end;
start = clock ();
delay (1000);
end = clock();
cout << “Time = ” << (end - start);
getch();
}
![Page 12: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/12.jpg)
Required Header Files# include <conio.h>
# include <fstream.h>
# include <dos.h>
# include <time.h>
![Page 13: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/13.jpg)
Reference
![Page 14: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/14.jpg)
Any Questions?
![Page 15: Computational Complexity](https://reader033.vdocument.in/reader033/viewer/2022052904/557c0569d8b42ad1658b4621/html5/thumbnails/15.jpg)
Thank You!