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

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

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

Sequences.......................<br />

251<br />

6.5<br />

Case Study: The Move-to-Front Heuristic<br />

......................<br />

253<br />

6.5.1<br />

Us<strong>in</strong>g a Sorted List <strong>and</strong> a Nested Class.......<br />

253<br />

6.5.2<br />

Us<strong>in</strong>g a List with the Move-to-Front Heuristic....<br />

256<br />

6.5.3<br />

Possible Uses of a Favorites List...........<br />

257<br />

6.6<br />

Exercises ......................<br />

260<br />

java.datastructures.net<br />

6.1 Array Lists<br />

Suppose we have a collection S of n elements stored <strong>in</strong> a certa<strong>in</strong> l<strong>in</strong>ear order, so that<br />

we can refer to the elements <strong>in</strong> S as first, second, third, <strong>and</strong> so on. Such a collection is<br />

generically referred to as a list or sequence. We can uniquely refer to each element e<br />

<strong>in</strong> S us<strong>in</strong>g an <strong>in</strong>teger <strong>in</strong> the range [0,n − 1] that is equal to the number of elements of S<br />

that precede e <strong>in</strong> S. The <strong>in</strong>dex of an element e <strong>in</strong> S is the number of elements that are<br />

before e <strong>in</strong> S. Hence, the first element <strong>in</strong> S has <strong>in</strong>dex 0 <strong>and</strong> the last element has <strong>in</strong>dex<br />

n − 1. Also, if an element of S has <strong>in</strong>dex i, its previous element (if it exists) has <strong>in</strong>dex<br />

i − 1, <strong>and</strong> its next element (if it exists) has <strong>in</strong>dex i + 1. This concept of <strong>in</strong>dex is related<br />

313

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

Saved successfully!

Ooh no, something went wrong!