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.

Table 8.3: Performance of a priority queue realized<br />

by means of a heap, which is <strong>in</strong> turn implemented with<br />

an array list or l<strong>in</strong>ked structure. We denote with n the<br />

number of entries <strong>in</strong> the priority queue at the time a<br />

method is executed. The space requirement is O(n).<br />

The runn<strong>in</strong>g time of operations <strong>in</strong>sert <strong>and</strong> removeM<strong>in</strong><br />

is worst case for the array-list implementation of the<br />

heap <strong>and</strong> amortized for the l<strong>in</strong>ked representation.<br />

Operation<br />

Time<br />

size, isEmpty<br />

O(1)<br />

m<strong>in</strong>,<br />

O(1)<br />

<strong>in</strong>sert<br />

O(logn)<br />

removeM<strong>in</strong><br />

O(logn)<br />

In short, each of the priority queue ADT methods can be performed <strong>in</strong> O(1) or <strong>in</strong><br />

O(logn) time, where n is the number of entries at the time the method is executed.<br />

The analysis of the runn<strong>in</strong>g time of the methods is based on the follow<strong>in</strong>g:<br />

• The heap T has n nodes, each stor<strong>in</strong>g a reference to an entry.<br />

• Operations add <strong>and</strong> remove on T take either O(1) amortized time (arraylist<br />

representation) or O(logn) worst-case time.<br />

• In the worst case, up-heap <strong>and</strong> down-heap bubbl<strong>in</strong>g perform a number of<br />

swaps equal to the height of T.<br />

• The height of heap T is O(logn), s<strong>in</strong>ce T is complete (Proposition 8.5).<br />

484

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

Saved successfully!

Ooh no, something went wrong!