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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

them. One solution is the adjacency matrix, which is a two-dimensional array<br />

of integers representing the distances between towns. An example is shown in<br />

Fig. 2.6. Here, we have five towns connected by roads of a given length. We<br />

declare a two-dimensional array distance[5][5] to store the distance between<br />

any two towns.<br />

Town 0<br />

45<br />

15<br />

Town 4<br />

45<br />

50<br />

Town 2<br />

50<br />

52<br />

Town 1<br />

30<br />

Town 3<br />

Town<br />

0<br />

1<br />

2<br />

3<br />

4<br />

0 1<br />

Town<br />

2 3 4<br />

−1 50 15 −1 45<br />

50 −1 −1 30 −1<br />

15 −1 −1 50 45<br />

−1 30 50 −1 52<br />

45 −1 45 52 −1<br />

Fig. 2.6. Example map <strong>and</strong> its corresponding adjacency matrix<br />

The distance is then found by reading the contents of array element<br />

distance[firsttown][secondtown]. Notice that for each town n, distance[n][n]<br />

has the value -1, as it makes no sense for a town to have a distance to itself.<br />

Also, if there is no direct road connecting town x <strong>and</strong> town y, then<br />

distance[x][y] also takes the value -1. The final thing to note about the adjacency<br />

matrix is that as the roads are two-way, the matrix is symmetrical in<br />

the diagonal (i.e., distance[x][y] has the same value as distance[y][x]). Obviously,<br />

this is not the most efficient method of storing undirected graphs, but<br />

it provides an easy illustration of the use of more complicated data structures.<br />

Graphs<br />

As we have seen, an example problem may be phrased thus: given a set of<br />

towns connected by roads, what is the shortest path between town A <strong>and</strong><br />

town B? Another problem may ask if, given a map of mainl<strong>and</strong> Europe, it<br />

is possible to color each country red, green, or blue such that no adjacent<br />

countries are colored the same.<br />

The first example is referred to as an optimisation problem, as we are required<br />

to find a path that fits some criterion (i.e., it is the shortest possible<br />

path). The second example is known as a decision problem, as we are answering<br />

a simple “‘yes/no” question about a structure. A large body of problems<br />

is concerned with the mathematical structures known as graphs. Inthiscontext,<br />

a graph is not a method of visualising data, rather a network of points<br />

<strong>and</strong> lines. More formally, a graph, G =(V,E), is a set of points (vertices), V ,<br />

connected by a set of lines (edges), E. Take the fragment of an English county<br />

map depicted in Fig. 2.7.

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

Saved successfully!

Ooh no, something went wrong!