Java Reference
In-Depth Information
Comparing Searches
As far as the search algorithms go, there is no doubt that the binary search approach
is far more efficient than the linear search. However, the binary search requires that
the data be sorted. So once again, the algorithm to choose depends on the situation.
If it's relatively easy to keep the data sorted, or if there will be a lot of search-
ing, it will likely be more appropriate to use a binary search. On the other hand,
a linear search is quite simple to implement and may be the best choice when
long-term efficiency is not an issue.
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 10.17 Given the following list of numbers, how many elements of the list
would be examined by the linear search algorithm to determine if
each of the indicated target elements are on the list?
15 21 4 17 8 27 1 22 43 57 25 7 53 12 16
a. 17
b. 15
c. 16
d. 45
SR 10.18 Describe the general concept of a binary search.
SR 10.19 Given the following list of numbers, how many elements of the list
would be examined by the binary search algorithm to determine if
each of the indicated target elements are on the list?
1 4 7 8 12 15 16 17 21 22 25 27 43 53 57
a. 17
b. 15
c. 57
d. 45
10.6 Designing for Polymorphism
We've been evolving the concepts underlying good software design throughout
this topic. For every aspect of object-oriented software, we should make decisions,
consciously and carefully, that lead to well-structured, flexible, and elegant code.
We want to define appropriate classes and objects, with proper encapsulation. We
want to define appropriate relationships among the classes and objects, including
leveraging the powerful aspects of inheritance when possible. Now we can add
polymorphism to our set of intellectual tools for thinking about software design.
 
Search WWH ::




Custom Search