Answers to Self-Review Exercises

16.1
  1. 16, because an O(n2) algorithm takes 16 times as long to sort four times as much information.

  2. O(n logn).

16.2Both of these algorithms incorporate “halving”—somehow reducing something by half. The binary search eliminates from consideration one half of the array after each comparison. The merge sort splits the array in half each time it is called.
16.3The insertion sort is easier to understand and to program than the merge sort. The merge sort is far more efficient [O(n logn) ] than the insertion sort [O(n2)].
16.4In a sense, it does not really sort these two subarrays. It simply keeps splitting the original array in half until it provides a one-element subarray, which is, of course, sorted. It then builds up ...

Get Java™ How to Program, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.