20.1 Introduction

Searching data involves determining whether a value (referred to as the search key) is present in the data and, if so, finding the value’s location. Two popular search algorithms are the simple linear search (Section 20.2.1) and the faster but more complex binary search (Section 20.2.2).

Sorting places data in ascending or descending order, based on one or more sort keys. A list of names could be sorted alphabetically, bank accounts could be sorted by account number, employee payroll records could be sorted by social security number, and so on. You’ll learn about insertion sort (Section 20.3.1), selection sort (Section 20.3.2) and the more efficient, but more complex merge sort (Section 20.3.3). Figure 20.1 summarizes the ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.