complexity of algorithm

14
Bismillah-e-Rahman-e- Raheem COMPLEXITY OF ALGORITHM AND COST_TIME TRADE OFF

Upload: muhammad-muzammal

Post on 06-May-2015

26.650 views

Category:

Education


2 download

DESCRIPTION

Complexity of Algorithm and Space-Time Trade-off

TRANSCRIPT

Page 1: Complexity of Algorithm

Bismillah-e-Rahman-e-Raheem

COMPLEXITY OF ALGORITHM AND

COST_TIME TRADE OFF

Page 2: Complexity of Algorithm

Muhammad Muzammal Muhammad Muzammal

E-Mail: [email protected]: [email protected]

By By

Page 3: Complexity of Algorithm

Introduction

Algorithm

An algorithm is a finite set of well-defined instructions for accomplishing some task, which given an initial state, will terminate in a defined end-state.

Page 4: Complexity of Algorithm

Complexity of algorithms

Complexity of algorithms

The complexity of an algorithm is a function f (n) which measures the time and space used by an algorithm in terms of input size n.

In computer science, the complexity of an algorithm is a way to classify how efficient an algorithm is, compared to alternative ones. The focus is on how execution time increases with the data set to be processed.

The computational complexity and efficient implementation of the algorithm are important in computing, and this depends on suitable data structures.

Page 5: Complexity of Algorithm

Complexity of algorithms

Description of ComplexityDifferent algorithms may complete the same task with a different set of instructions in less or more time, space or effort than other. The analysis and study of algorithms is a discipline in Computer Science which has a strong mathematical background. It often relies on theoretical analysis of pseudo-code. To compare the efficiency of algorithms, we don't rely on abstract measures such as the time difference in running speed, since it too heavily relies on the processor power and other tasks running in parallel.

Page 6: Complexity of Algorithm

Classes of complexity

Polynomial time algorithms

•(C) --- Constant time --- the time necessary to perform the algorithm does not change in response to the size of the problem.

•(n) --- Linear time --- the time grows linearly with the size (n) of the problem.

• (n2) --- Quadratic time --- the time grows quadratically with the size (n) of the problem

Page 7: Complexity of Algorithm

Classes of complexity

Sub-linear time algorithms

• It grow slower than linear time algorithms• Super-polynomial time algorithms• It grows faster than polynomial time algorithms.• Exponential time --- the time required grows exponentially with the size of the problem.

Page 8: Complexity of Algorithm

Example of finding the complexity of an algorithm

BUBBLE SORT

For ( int I = 0 ; I < 5 ; I ++ )

For ( int j = 0 ; j < 4 ; j ++ )

If (A [ j ] > A [ j + 1 ] ) {

Temp = A [ j ] ;

A [ j ] = A [ j+1 ] ;

A [ j + 1 ] =Temp;

}

Page 9: Complexity of Algorithm

Complexity of Bubble Sort

The time for assorting algorithm is measured in the number of the comparisons. The number of f(n) of comparisons in the bubble sort is easily computed. Specifically ,there are n-1 comparisons during the 1st pass , which places the largest element in the last position ; there are n-2 comparisons in the 2nd step, which places the 2nd largest element in the next –to-last position; and so on.. In other words, the time required to execute the bubble sort algorithm is proportional to n2, where n is the number of input items.

Page 10: Complexity of Algorithm

Example of finding the complexity of an algorithm

Linear SearchInt array[10]={10,20,30,40,50,60,70,80,90,100};

Int I,n, Loc=-1;

Cout<<“Enter the value to find “;

Cin>>n;

For(i=0;I<10;I++)

if(array[I]==n)

Loc=I;

If(Loc==-1)

Cout<<“Value not found”;

Else

Cout<<“The value”<<n<<“is found at index “<<Loc;

Page 11: Complexity of Algorithm

Space-time tradeoff

In computer science, a space-time tradeoff refers to a choice between algorithmic solutions of a data processing problem that allows one to derease the running time of an algorithmic solution by increasing the space to store the data and vice versa. The computation time can be reduced at the cost of increased memory use. As the relative costs of CPU cycles, RAM space, and hard drive space change — hard drive space has for some time been getting cheaper at a much faster rate than other components of computers, the appropriate choices for space-time tradeoffs have changed radically. Often, by exploiting a space-time tradeoff, a program can be made to run much faster.

Page 12: Complexity of Algorithm

Space-time tradeoff

A space-time tradeoff can be applied to the problem of data storage. If data is stored uncompressed, it takes more space but less time than if the data were stored compressed (since compressing the data reduces the amount of space it takes, but it takes time to run the compression algorithm). Depending on the particular instance of the problem, either way is practical.

Page 13: Complexity of Algorithm

Continued…

Larger code size can be traded for higher program speed when applying loop unwinding. This technique makes the code longer for each iteration of a loop, but saves the computation time required for jumping back to the beginning of the loop at the end of each iteration.

Algorithms that make use of space-time tradeoffs to achieve better running times include the baby-step giant-step algorithm for calculating discrete logarithms

Page 14: Complexity of Algorithm

Using Genetic Algorithms to Solve Construction Time-Cost Trade-Off Problems

Existing methods for time-cost trade-off analysis focus on using heuristics or mathematical programming. These methods, however, are not efficient enough to solve large-scale CPM networks (hundreds of activities or more). Analogous to natural selection and genetics in reproduction, genetic algorithms (GAs) have been successfully adopted to solve many science and engineering problems and have proven to be an efficient means for searching optimal solutions in a large problem domain computer program that can execute the algorithm efficiently.