Searching Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential searches Discuss the relative merits of different sequential searches Design and implement binary searches Design and implement hash-list searches Discuss the merits of different collision resolution algorithms Data Structures: A Pseudocode Approach with C, Second Edition
13-1 List Searches Sequential Search Variations on Sequential Searches In this section we study searches that work with arrays. The two basic searches for arrays are the sequential search and the binary search. Sequential Search Variations on Sequential Searches Binary Search Analyzing Search Algorithms Data Structures: A Pseudocode Approach with C, Second Edition
Searching The process used to find the location of a target among a list of objects. Data Structures: A Pseudocode Approach with C, Second Edition
List searches Sequential search Variations of sequential search Sentinel search Probability search Ordered list search Binary search Data Structures: A Pseudocode Approach with C, Second Edition
Sequential search The sequential search is used whenever the list is not ordered. Data Structures: A Pseudocode Approach with C, Second Edition
Successful search of an unordered list Data Structures: A Pseudocode Approach with C, Second Edition
Unsuccessful search in unordered list Data Structures: A Pseudocode Approach with C, Second Edition
Sequential search algorithm Data Structures: A Pseudocode Approach with C, Second Edition
Variations on sequential searches Sentinel search Probability search The data in the array are arranged with the most probable search elements at the beginning of the array and the least probable at the end. Ordered list search Data Structures: A Pseudocode Approach with C, Second Edition
Sentinel search algorithm Data Structures: A Pseudocode Approach with C, Second Edition
Probability search algorithm Data Structures: A Pseudocode Approach with C, Second Edition
Ordered list search algorithm Data Structures: A Pseudocode Approach with C, Second Edition
Binary search The list must be sorted. The list starts to become large. Contains more than 16 elements. mid = (begin + end) / 2 Data Structures: A Pseudocode Approach with C, Second Edition
Binary search example Data Structures: A Pseudocode Approach with C, Second Edition
Unsuccessful binary search example Figure 2-5 Unsuccessful binary search example Data Structures: A Pseudocode Approach with C, Second Edition
Data Structures: A Pseudocode Approach with C, Second Edition
(continued) Data Structures: A Pseudocode Approach with C, Second Edition
Analyzing search algorithms The efficiency of the sequential search is O(n). The efficiency of the binary search is O(log n). List size Iterations binary sequential 16 4 50 6 256 8 1000 10 10000 14 100000 17 1000000 20 Data Structures: A Pseudocode Approach with C, Second Edition
13-2 Search Implementations Having discussed the basic concepts of array searches, we write C implementations of the two most common. Sequential Search in C Binary Search In C Data Structures: A Pseudocode Approach with C, Second Edition
Sequential Search in C Data Structures: A Pseudocode Approach with C, Second Edition
Data Structures: A Pseudocode Approach with C, Second Edition
Binary Search In C Data Structures: A Pseudocode Approach with C, Second Edition
Data Structures: A Pseudocode Approach with C, Second Edition