# ch19 - Searching data involves determining whether a...

This preview shows pages 1–5. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Searching data involves determining whether a value (referred to as the search key ) is present in the data and, if so, finding its location. Two popular search algorithms are the simple linear search and the faster but more complex binary search. Sorting places data in ascending or descending order, based on one or more sort keys . This chapter introduces two simple sorting algorithms, the selection sort and the insertion sort Figure 19.1 summarizes the searching and sorting algorithms discussed in the examples and exercises of this book.
The next two subsections discuss two common search algorithms—one that is easy to program yet relatively inefficient and one that is relatively efficient but more complex and difficult to program.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The linear search algorithm searches each element in an array sequentially. If the search key does not match an element in the array, the algorithm tests each element, and when the end of the array is reached, informs the user that the search key is not present. If the search key is in the array, the algorithm tests each element until it finds one that matches the search key and returns the index of that element. If there are duplicate values in the array, linear search returns the index of the first element in the array that matches the search key. Arrays
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 39

ch19 - Searching data involves determining whether a...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online