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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

11.1.3 The Runn<strong>in</strong>g Time of Merge-Sort<br />

Now that we have given the details of the merge-sort algorithm, <strong>in</strong> both its<br />

arraybased <strong>and</strong> list-based versions, <strong>and</strong> we have analyzed the runn<strong>in</strong>g time ofthe<br />

crucial merge algorithm used <strong>in</strong> the conquer step, let us analyze the runn<strong>in</strong>g time of<br />

the entire merge-sort algorithm, assum<strong>in</strong>g it is given an <strong>in</strong>put sequence of n<br />

elements. For simplicity, we restrict our attention to the case where n is a power of<br />

2. We leave it to an exercise (R-11.6) to show that the result of our analysis also<br />

holds when n is not a power of 2.<br />

As we did <strong>in</strong> the analysis of the merge algorithm, we assume that the <strong>in</strong>put<br />

sequence S <strong>and</strong> the auxiliary sequences S 1 <strong>and</strong> S 2 , created by each recursive call of<br />

686

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

Saved successfully!

Ooh no, something went wrong!