Professional Documents
Culture Documents
Elementary Numerical Analysis: Algorithm Analysis
Elementary Numerical Analysis: Algorithm Analysis
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
Reasons:
– modern operating systems are multitasking;
– multiple evaluation needed (due to random factors presence)
– different input data sets must be processed.
Interpolation
and approximation Trend
of results is possble
Number of elements
void main(void)
{
double sum = 0 , ai;
int f = 1 , i = 1;
Requirements:
– has to take into account the different types of input data;
Title: An algorithm for counting the number of array elements equal to zero
Baseline data: Array A
Required: the number of elements equal to zero
Start
Put the number of K = 0
CYCLE for all elements of the array from 1 to ElementsNumber(A)
1. O k f O f
(constant multipliers are not important)
2. O f g O f O g , O f g O f O g
Example: O 17 N N O17 N O N O N O N O N N O N 2
Example: O N 5 N 2 O N 5
O(1): Most of the operations in the program are executed only once or only a few times.
Algorithms of constant complexity.
О(N): Every element of input data is to be processed only a linear number of times.
1. O k f O f
2. O f g O f O g , O f g O f O g
3. O f g is equal to dominant of O f and O g
Elementary numerical analysis: algorithm analysis
Algorithm analysis
Example 2: Pn(x) = anxn + an-1xn-1 + ... + aixi + ... + a1x1 + a0
For example,
P3(x) = a3x^3 + a2x^2 + a1x^1 + a0 = a0 + x(a1 + x(a2 + a3x))
1*, 1+ 1 *, 1+
n-1 brackets totally
Totally: n multiplications + n additions = 2n. O n
1. O k f O f
2. O f g O f O g , O f g O f O g
3. O f g is equal to dominant of O f and O g
Elementary numerical analysis: algorithm analysis
Algorithm analysis
Exercise:
3) 2100 O ? O1
1
4) 5n O ? O
n
1. O k f O f
2. O f g O f O g , O f g O f O g
3. O f g is equal to dominant of O f and O g
Elementary numerical analysis: algorithm analysis
Algorithm analysis
Example:
If N = 100 000 pages, we have to open the book log2 100000 ≈ 17 times.
Donald Knuth
born January 10, 1938
Homepage: http://www-cs-staff.stanford.edu/~uno/
Num | X | Y(X) |
-------------------------------
0 | 1.5 | 2.74 |
1 | 1.6 | 3.21 |
...
...
Note: write your student number and english name in the first
line of your program as a comment: