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.

The variation of heap-sort above is said to be <strong>in</strong>-place because we use only a<br />

small amount of space <strong>in</strong> addition to the sequence itself. Instead of transferr<strong>in</strong>g<br />

elements out of the sequence <strong>and</strong> then back <strong>in</strong>, we simply rearrange them. We il<br />

lustrate <strong>in</strong>-place heap-sort <strong>in</strong> Figure 8.9. In general, we say that a sort<strong>in</strong>g<br />

algorithm is <strong>in</strong>-place if it uses only a small amount of memory <strong>in</strong> addition to the<br />

sequence stor<strong>in</strong>g the objects to be sorted.<br />

Figure 8.9: First three steps of Phase 1 of <strong>in</strong>-place<br />

heap-sort. The heap portion of the sequence is<br />

highlighted <strong>in</strong> blue. We draw next to the sequence a<br />

b<strong>in</strong>ary tree view of the heap, even though this tree is<br />

not actually constructed by the <strong>in</strong>-place algorithm.<br />

490

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

Saved successfully!

Ooh no, something went wrong!