Lecture Preview: Searching

(Suggested book reading: Programming Abstractions in C++, section 7.5, 10.1)

Today we will discuss various algorithms for searching for a value in a vector of data. The most straightforward algorithm is to start at the beginning of the vector and loop across it, which is called a sequential search. If the data in the vector is sorted, a more efficient algorithm is to repeatedly look at the middle element and eliminate half of the data until the target is found. This is called a binary search.

figure

This document and its content are copyright © Marty Stepp, 2015. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the authors' expressed written permission.