CHAPTER 4
SEARCH AND SORT ALGORITHMS
The first half of this chapter provides an introduction to some well-known search algorithms, followed by the second half that discusses various sorting algorithms.
The first section of this chapter introduces search algorithms such as linear search and binary search, that you can use when searching for an item (which can be numeric or character-based) in an array. A linear search is inefficient because it requires an average of n/2 (which has complexity O[n]) comparisons to determine whether or not the search element is in the array, where n is the number of elements in the list or array.
By contrast, a binary search required O (log n) comparisons, which is vastly more efficient with larger sets of items. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access