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.

s<strong>in</strong>ce <strong>in</strong>sert<strong>in</strong>g elements at the end of a sequence is a constant-time operation<br />

<strong>in</strong>dependent of whether the sequence is implemented as an array or a l<strong>in</strong>ked list.<br />

Code Fragment 11.5: Quick-sort for an <strong>in</strong>put<br />

sequence S implemented with a l<strong>in</strong>ked list or an array.<br />

Runn<strong>in</strong>g Time of Quick-Sort<br />

We can analyze the runn<strong>in</strong>g time of quick-sort with the same technique used for<br />

merge-sort <strong>in</strong> Section 11.1.3. Namely, we can identify the time spent at each node<br />

of the quick-sort tree T <strong>and</strong> sum up the runn<strong>in</strong>g times for all the nodes.<br />

Exam<strong>in</strong><strong>in</strong>g Code Fragment 11.5, we see that the divide step <strong>and</strong> the conquer step of<br />

quick-sort can be implemented <strong>in</strong> l<strong>in</strong>ear time. Thus, the time spent at a node v of T<br />

is proportional to the <strong>in</strong>put size s(v) of v, def<strong>in</strong>ed as the size of the sequence<br />

h<strong>and</strong>led by the <strong>in</strong>vocation of quick-sort associated with node v. S<strong>in</strong>ce subsequence<br />

700

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

Saved successfully!

Ooh no, something went wrong!