Java Reference
In-Depth Information
7. When the preceding while loop ends, the loop condition must be false,
that is, iFirst >= first.length or
iSecond >= second.length (De Morgan's Law). Then
first.length - iFirst <= 0 or iSecond.length -
iSecond <= 0 .
8. First sort 8 7 6 5. Recursively, first sort 8 7. Recursively, first sort 8. It's
sorted. Sort 7. It's sorted. Merge them: 7 8. Do the same with 6 5 to get 5 6.
Merge them to 5 6 7 8. Do the same with 4 3 2 1: Sort 4 3 by sorting 4 and
3 and merging them to 3 4. Sort 2 1 by sorting 2 and 1 and merging them to
1 2. Merge 3 4 and 1 2 to 1 2 3 4. Finally, merge 5 6 7 8 and 1 2 3 4 to 1 2
3 4 5 6 7 8.
9. Approximately 100,000 – log(100,000) / 50,000 – log(50,000)=2 – 5 /
4.7=2.13 times the time required for 50,000 values. That's 2.13 – 97
milliseconds or approximately 207 milliseconds.
10. By calling Arrays.sort(values) .
11. On average, you'd make 500,000 comparisons.
12. The search method returns the index at which the match occurs, not the
data stored at that location.
13. You would search about 20. (The binary log of 1,024 is 10.)
14. Then you know where to insert it so that the array stays sorted, and you can
keep using binary search.
15. Otherwise, you would not know whether a value is present when the
method returns 0.
16. The Rectangle class does not implement the Comparable interface.
17. The BankAccount class needs to implement the Comparable
interface. Its compareTo method must compare the bank balances.
Search WWH ::




Custom Search