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.

Projects<br />

P-10.1<br />

N-body simulations are an important model<strong>in</strong>g tool <strong>in</strong> physics, astronomy, <strong>and</strong><br />

chemistry. In this project, you are to write a program that performs a simple n-<br />

body simulation called "Jump<strong>in</strong>g Leprechauns." This simulation <strong>in</strong>volves n<br />

leprechauns, numbered 1 to n. It ma<strong>in</strong>ta<strong>in</strong>s a gold value g for each leprechaun i,<br />

which beg<strong>in</strong>s with each leprechaun start<strong>in</strong>g out with a million dollars worth of<br />

gold, that is, g = 1000000 for eachi= 1,2,... ,n. In addition, the simulation also<br />

ma<strong>in</strong>ta<strong>in</strong>s, for each leprechaun i, a place on the horizon, which is represented as<br />

a double-precision float<strong>in</strong>g po<strong>in</strong>t number, x i . In each iteration of the simulation,<br />

the simulation processes the leprechauns <strong>in</strong> order. Process<strong>in</strong>g a leprechaun i<br />

dur<strong>in</strong>g this iteration beg<strong>in</strong>s by comput<strong>in</strong>g a new place on the horizon for i,<br />

which is determ<strong>in</strong>ed by the assignment<br />

x i ←x i + rg i ,<br />

where r is a r<strong>and</strong>om float<strong>in</strong>g-po<strong>in</strong>t number between −1 <strong>and</strong> 1. Leprechaun i then<br />

steals half the gold from the nearest leprechauns on either side of him <strong>and</strong> adds<br />

this gold to his gold value, g i . Write a program that can perform a series of<br />

iterations <strong>in</strong> this simulation for a given number, n, of leprechauns. Try to<br />

<strong>in</strong>clude a visualization of the leprechauns <strong>in</strong> this simulation, <strong>in</strong>clud<strong>in</strong>g their gold<br />

values <strong>and</strong> horizon positions. You must ma<strong>in</strong>ta<strong>in</strong> the set of horizon positions<br />

us<strong>in</strong>g an ordered dictionary data structure described <strong>in</strong> this chapter.<br />

P-10.2<br />

Extend class B<strong>in</strong>arySearchTree (Code Fragments 10.3–10.5) to support<br />

the methods of the ordered dictionary ADT (see Section 9.5.2).<br />

P-10.3<br />

Implement a class RestructurableNodeB<strong>in</strong>aryTree that supports the<br />

methods of the b<strong>in</strong>ary tree ADT, plus a method restructure for perform<strong>in</strong>g a<br />

rotation operation. This class is a component of the implementation of an AVL<br />

tree given <strong>in</strong> Section 10.2.2.<br />

P-10.4<br />

Write a <strong>Java</strong> class that implements all the methods of the ordered dictionary<br />

ADT (see Section 9.5.2) us<strong>in</strong>g an AVL tree.<br />

P-10.5<br />

Write a <strong>Java</strong> class that implements all the methods of the ordered dictionary<br />

ADT (see Section 9.5.2) us<strong>in</strong>g a (2,4) tree.<br />

673

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

Saved successfully!

Ooh no, something went wrong!