Java Reference
In-Depth Information
toString
java.util.Collections
binarySearch
sort
java.util.Comparator<T>
compare
REVIEW EXERCISES
΢΢Exercise R14.1. Checking against off-by-one errors. When writing the
selection sort algorithm of Section 14.1 , a programmer must make the
usual choices of < against < = , a.length against
a.length - 1 , and from against from + 1 . This is a fertile ground
for off-by-one errors. Conduct code walkthroughs of the algorithm with
arrays of length 0, 1,2, and 3 and check carefully that all index values are
correct.
΢ Exercise R14.2. What is the difference between searching and sorting?
΢΢Exercise R14.3. For the following expressions, what is the order of the
growth of each?
a. n 2 +2n+1
b. n 10 +9n 9 +20n 8 +145n 7
c. (n+1) 4
d. (n 2 +n) 2
e. n+0.001n 3
f. n 3 ɨ1000n 2 +10 9
g. n+log(n)
h. n 2 +n log(n)
i. 2 n +n 2
Search WWH ::




Custom Search