23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

position of the reference to v's type will tell us the place where this edge belongs<br />

<strong>in</strong> v's adjacency list. Thus, whether we use this edge-swapp<strong>in</strong>g trick or a count<br />

identifier, we can implement DFS <strong>in</strong>-place without affect<strong>in</strong>g its asymptotic<br />

runn<strong>in</strong>g time.<br />

14.2 External Memory <strong>and</strong> Cach<strong>in</strong>g<br />

There are several computer applications that must deal with a large amount of data.<br />

Examples <strong>in</strong>clude the analysis of scientific data sets, the process<strong>in</strong>g of f<strong>in</strong>ancial<br />

transactions, <strong>and</strong> the organization <strong>and</strong> ma<strong>in</strong>tenance of databases (such as telephone<br />

directories). In fact, the amount of data that must be dealt with is often too large to fit<br />

entirely <strong>in</strong> the <strong>in</strong>ternal memory of a computer.<br />

14.2.1 The Memory Hierarchy<br />

In order to accommodate large data sets, computers have a hierarchy of different<br />

k<strong>in</strong>ds of memories, which vary <strong>in</strong> terms of their size <strong>and</strong> distance from the CPU.<br />

Closest to the CPU are the <strong>in</strong>ternal registers that the CPU itself uses. Access to such<br />

locations is very fast, but there are relatively few such locations. At the second level<br />

<strong>in</strong> the hierarchy is the cache memory. This memory is considerably larger than the<br />

register set of a CPU, but access<strong>in</strong>g it takes longer (<strong>and</strong> there may even be multiple<br />

caches with progressively slower access times). At the third level <strong>in</strong> the hierarchy is<br />

the <strong>in</strong>ternal memory, which is also known as ma<strong>in</strong> memory or core memory. The<br />

<strong>in</strong>ternal memory is considerably larger than the cache memory, but also requires<br />

more time to access. F<strong>in</strong>ally, at the highest level <strong>in</strong> the hierarchy is the external<br />

memory, which usually consists of disks, CD drives, DVD drives, <strong>and</strong>/or tapes.<br />

This memory is very large, but it is also very slow. Thus, the memory hierarchy for<br />

computers can be viewed as consist<strong>in</strong>g of four levels, each of which is larger <strong>and</strong><br />

slower than the previous level. (See Figure 14.3.)<br />

In most applications, however, only two levels really matter—the one that can hold<br />

all data items <strong>and</strong> the level just below that one. Br<strong>in</strong>g<strong>in</strong>g data items <strong>in</strong> <strong>and</strong> out of the<br />

higher memory that can hold all items will typically be the computational<br />

bottleneck <strong>in</strong> this case.<br />

Figure 14.3: The memory hierarchy.<br />

894

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

Saved successfully!

Ooh no, something went wrong!