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.

P-8.10<br />

One of the ma<strong>in</strong> applications of priority queues is <strong>in</strong> operat<strong>in</strong>g systems for<br />

schedul<strong>in</strong>g jobs on a CPU. In this project you are to build a program that<br />

schedules simulated CPU jobs. Your program should run <strong>in</strong> a loop, each<br />

iteration of which corresponds to a time slice for the CPU. Each job is assigned<br />

a priority, which is an <strong>in</strong>teger between -20 (highest priority) <strong>and</strong> 19 (lowest<br />

priority), <strong>in</strong>clusive. From among all jobs wait<strong>in</strong>g to be pro cessed <strong>in</strong> a time slice,<br />

the CPU must work on a job with highest priority. In this simulation, each job<br />

will also come with a length value, which is an <strong>in</strong>teger between 1 <strong>and</strong> 100,<br />

<strong>in</strong>clusive, <strong>in</strong>dicat<strong>in</strong>g the number of time slices that are needed to process this<br />

job. For simplicity, you may assume jobs cannot be <strong>in</strong>terrupted—once it is<br />

scheduled on the CPU, a job runs for a number of time slices equal to its length.<br />

Your simulator must output the name of the job runn<strong>in</strong>g on the CPU <strong>in</strong> each<br />

time slice <strong>and</strong> must process a sequence of comm<strong>and</strong>s, one per time slice, each<br />

of which is of the form "add job name with length n <strong>and</strong> priority p" or "no new<br />

job this slice".<br />

Chapter Notes<br />

Knuth's book on sort<strong>in</strong>g <strong>and</strong> search<strong>in</strong>g [63] describes the motivation <strong>and</strong> history for<br />

the selection-sort, <strong>in</strong>sertion-sort, <strong>and</strong> heap-sort algorithms. The heap-sort algorithm is<br />

due to Williams [99], <strong>and</strong> the l<strong>in</strong>ear-time heap construction algorithm is due to Floyd<br />

[36]. Additional algorithms <strong>and</strong> analyses for heaps <strong>and</strong> heap-sort variations can be<br />

found <strong>in</strong> papers by Bentley [13], Carlsson [21], Gonnet <strong>and</strong> Munro [42], McDiarmid<br />

<strong>and</strong> Reed [71], <strong>and</strong> Schaffer <strong>and</strong> Sedgewick [85]. The design pattern of us<strong>in</strong>g<br />

location-aware entries (also described <strong>in</strong> [43]) appears to be new.<br />

512

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

Saved successfully!

Ooh no, something went wrong!