Analysis of Algorithms
Analysis of Algorithms
What is Algorithm?
Ans:
If the program is run on a large data set, then the running time becomes an issue.
We make algorithm and test it before running the actual program.
Complexity of Algorithm?
There are 2 types of complexity we face in the algorithm.
Space complexity is related to how much space a algorithm takes in the memory.
Algorithm 2:
(1) Read the first k elements into an array and sort them in decreasing order
N =100 and k = 1?
Pass a input from algorithm if it stop at right answer the algorithm is called
correct.
If the out algorithm stop at and give wrong output the algorithm is called
incorrect algorithm.
Analyzing an algorithm:
First of all predict the resources that the algorithm needs.
These resources include.
Memory
Communication bandwidth
Computational time
Keep in mind that There are many fectors that effect the running time of the
algorithm these are below.
computer
compiler
algorithm used
input to the algorithm
The content of the input affects the running time their size may affect.
Run the instructions one after one on the same computer and analyze their
outputs.
Example:
Calculate ∑𝑛𝑖=1 𝑖2
2N+2
4N
1
Lines 1 and 4 count for one unit each
Line 3: executed N times, each time four units
Line 2: (1 for initialization, N+1 for all the tests, N for all the increments)
total 2N + 2
total cost: 6N + 4 O(N)
An upper bound on the running time for any input guarantee that the
algorithm will never take longer
The worst case can occur fairly often in searching a database for a particular
piece of information