Chapter 13. Searching: Finding What You Need
Sorting your collections can be costly, but often this represents a one-time cost after the collection has been created. However, this time and energy spent up front can significantly improve performance once in the life of your application's run cycle. Even adding a new object is a much less costly process when the object is added to an already sorted collection.
The real performance improvement comes when it is time to search your collections for specific elements or values. In this chapter, we will examine how sorted collections greatly improve search time, depending on the search algorithm you choose. We will not discuss all of the search algorithms you can choose from, but we will examine three of the most common ones:
- Linear search (sequential search)
- Binary search
- Jump search