22
© Pearson Education Limited, 2015
Answer: A
Explanation: A) This code sorts correctly. The other alternatives are missing braces, have
incorrect comparisons, or incorrect limits on their loops.
30) Although insertion sort and selection sort have generally the same O(n2) performance,
selection sort has an advantage of insertion sort. What is this advantage?
A) Selection sort usually makes fewer comparisons
B) Selection sort usually makes fewer swaps
C) Selection sort usually makes fewer passes
D) Selection sort usually makes fewer selections
E) none of the above
31) What kind of performance can you expect if you perform linear search on a sorted array?
A) The performance will be about the same as on an unsorted array
B) The performance will be much better than on an unsorted array
C) The performance will be much worse than on an unsorted array
D) The performance will be worse than n2 in this case
E) none of the above
32) Considering the event processing classes, what is the advantage of extending an adaptor class
compared to implementing an interface?
A) Adaptors save the programmer from having to create a collection of empty-bodied methods
B) Adaptors save the programmer from having to create inner classes
C) Adaptors can be used even when interfaces cannot
D) Adaptors are more efficient at run time
E) none of the above