13.12.2012 Views

Theoretical and Experimental DNA Computation (Natural ...

Theoretical and Experimental DNA Computation (Natural ...

Theoretical and Experimental DNA Computation (Natural ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

40 2 <strong>Theoretical</strong> Computer Science: A Primer<br />

Root<br />

Parents<br />

Child leaf nodes<br />

Fig. 2.14. An example tree<br />

faster (on the same computer) than one used to calculate the first million<br />

prime numbers. However, it is important be able to establish this fact with<br />

certainty. The field of computational complexity is concerned with the resources<br />

required by algorithms.<br />

Complexity may be defined as “the intrinsic minimum amount of resources,<br />

for instance, memory or time, needed to solve a problem or execute an algorithm.”<br />

In practice, we generally consider time as the limiting factor (that is,<br />

when discussing the relative complexity of algorithms, we consider the time<br />

taken for them to achieve their task).<br />

We measure the time complexity of an algorithm in terms of the number of<br />

computational “steps” it takes. For example, consider the factoring algorithm<br />

given in Sect. 2.4. We assume for the sake of argument than n>0. Step 1<br />

involves reading n. Step 2 is the conditional, checking if n ≤ 0. Step 3 assigns<br />

thevalue1tothepower variable. Then we enter a loop. This is the crucial<br />

part of the analysis, as it involves the section of the algorithm where most<br />

work is done. Step 4 checks the value of n. Aslongasn>0, we execute two<br />

assignment steps (to power <strong>and</strong> n). We then execute a final step to print out<br />

the value of power. Ascounter has the value n − 1, this algorithm takes two<br />

steps if n ≤ 0, <strong>and</strong> 5 + (n∗3) steps if n ≥ 0. Note that the constant 5 includes<br />

the final “while” step.<br />

However, consider the implementation of this algorithm on a computer.<br />

The running time of the program, given a particular value of n, still depends<br />

on two factors:<br />

1. The computer on which the program is run. Supercomputers execute instructions<br />

far more rapidly than personal computers,<br />

2. The conversion of the pseudo-code into machine language. Programs to<br />

do this are called compilers, <strong>and</strong> some compilers generate more efficient<br />

machine code than others. The number of machine instructions used to<br />

implement a particular pseudo-code statement will vary from compiler to<br />

compiler.<br />

We cannot therefore make statements like “this program will take 0.52 seconds<br />

to run for an input value of n = 1000”, unless we know the precise details of<br />

the machine <strong>and</strong> the compiler. Even then, the fact that the machine may or<br />

may not be carrying out other time-consuming tasks renders such predictions<br />

meaningless. Nobody is interested in the time complexity of an algorithm<br />

compiled in a particular way running on a particular machine in a particular

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!