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.

implementation for an ordered dictionary, say, one that uses a skip list, would be a<br />

good way to satisfy such queries. For example, call<strong>in</strong>g successors(k) on a<br />

query key k = (ORD, PVD, 05May, 09:30), could result <strong>in</strong> an iterator with the<br />

follow<strong>in</strong>g entries:<br />

((ORD, PVD, 05May, 09:53), (AA 1840, F5, Y15, 02:05,<br />

$251))<br />

((ORD, PVD, 05May, 13:29), (AA 600, F2, Y0, 02:16,<br />

$713))<br />

((ORD, PVD, 05May, 17:39), (AA 416, F3, Y9, 02:09,<br />

$365))<br />

((ORD, PVD, 05May, 19:50), (AA 1828, F9, Y25, 02:13,<br />

$186))<br />

Maxima Sets<br />

Life is full of trade-offs. We often have to trade off a desired performance<br />

measure aga<strong>in</strong>st a correspond<strong>in</strong>g cost. Suppose, for the sake of an example, we<br />

are <strong>in</strong>terested <strong>in</strong> ma<strong>in</strong>ta<strong>in</strong><strong>in</strong>g a database rat<strong>in</strong>g automobiles by their maximum<br />

speeds <strong>and</strong> their cost. We would like to allow someone with a certa<strong>in</strong> amount to<br />

spend to query our database to f<strong>in</strong>d the fastest car they can possibly afford.<br />

We can model such a trade-off problem as this by us<strong>in</strong>g a key-value pair to model<br />

the two parameters that we are trad<strong>in</strong>g off, which <strong>in</strong> this case would be the pair<br />

(cost, speed) for each car. Notice that some cars are strictly better than other<br />

cars us<strong>in</strong>g this measure. For example, a car with cost-speed pair (20,000,100) is<br />

strictly better than a car with cost-speed pair (30,000,90). At the same time, there<br />

are some cars that are not strictly dom<strong>in</strong>ated by another car. For example, a car<br />

with cost-speed pair (20000,100) may be better or worse than a car with costspeed<br />

pair (30000,120), depend<strong>in</strong>g on how much money we have to spend. (See<br />

Figure 9.13.)<br />

Figure 9.13: Illustrat<strong>in</strong>g the cost-performance tradeoff<br />

with key-value pairs represented by po<strong>in</strong>ts <strong>in</strong> the<br />

plane. Notice that po<strong>in</strong>t p is strictly better than po<strong>in</strong>ts<br />

c, d, <strong>and</strong> e, but may be better or worse than po<strong>in</strong>ts a,<br />

b, f, g, <strong>and</strong> h, depend<strong>in</strong>g on the price we are will<strong>in</strong>g to<br />

pay. Thus, if we were to add p to our set, we could<br />

remove the po<strong>in</strong>ts c, d, <strong>and</strong> e, but not the others.<br />

572

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

Saved successfully!

Ooh no, something went wrong!