18.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. This chapter presents two popular search algorithms—the simple linear search and the faster, but more complex, binary search. Sorting places data in 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. This chapter introduces two simple sorting algorithms, the selection sort and the insertion sort, and the more efficient, but more complex, merge sort. Figure 18.1 summarizes the searching and sorting capabilities in this book. We include this chapter for the benefit of computer-science students. Most programmers will use the .Net Framework’s built-in searching and sorting capabilities, such as class Array’s BinarySearch and Sort methods and similar capabilities in .NET collections (Chapter 21).

Fig. 18.1 Searching and sorting capabilities in this text.

Chapter Algorithm Location
Searching Algorithms:
18 Linear Search Section 18.2.1
Binary Search Section 18.2.2
Recursive Linear Search Exercise 18.8
Recursive Binary Search Exercise 18.9
21 BinarySearch method of class Array Fig. 21.3
ContainsKey method of class Dictionary<K, T> Fig. 21.4
Sorting Algorithms:
18 Selection Sort Section 18.3.1
Insertion Sort Section 18.3.2
Recursive Merge Sort Section 18.3.3
Bubble Sort Exercises 18.518.6
Bucket Sort Exercise 18.7
Recursive Quicksort Exercise 18.10
18, 21 Sort method of classes Array Figs. 18.3 and 21.3
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset