data structures: a pseudocode approach with c, second edition 1 chapter 13 objectives upon...
TRANSCRIPT
![Page 1: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/1.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 1
Chapter 13Chapter 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
SearchingSearching
![Page 2: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/2.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 2
13-1 List Searches
In this section we study searches that work with arrays. The two In this section we study searches that work with arrays. The two basic searches for arrays are the sequential search and the basic searches for arrays are the sequential search and the binary search.binary search.
• Sequential Search• Variations on Sequential Searches• Binary Search• Analyzing Search Algorithms
![Page 3: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/3.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 3
Searching
The process used to find the location of a target among a list of objects.
![Page 4: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/4.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 4
List searches
Sequential search Variations of sequential search
Sentinel search Probability search Ordered list search
Binary search
![Page 5: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/5.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 5
Sequential search
The sequential search is used whenever the list is not ordered.
![Page 6: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/6.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 6
Successful search of an unordered list
![Page 7: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/7.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 7
Unsuccessful search in unordered list
![Page 8: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/8.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 8
Sequential search algorithm
![Page 9: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/9.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 9
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
![Page 10: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/10.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 10
Sentinel search algorithm
![Page 11: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/11.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 11
Probability search algorithm
![Page 12: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/12.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 12
Ordered list search algorithm
![Page 13: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/13.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 13
Binary search
The list must be sorted. The list starts to become large.
Contains more than 16 elements.
mid = (begin + end) / 2
![Page 14: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/14.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 14
Binary search example
2
2
lastfirstmid
endbeginmid
![Page 15: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/15.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 15
Figure 2-5
Unsuccessful binary search example
![Page 16: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/16.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 16
![Page 17: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/17.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 17
(continued)
![Page 18: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/18.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 18
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 16
50 6 50
256 8 256
1000 10 1000
10000 14 10000
100000 17 100000
1000000 20 1000000
![Page 19: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/19.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 19
13-2 Search Implementations
Having discussed the basic concepts of array searches, we write Having discussed the basic concepts of array searches, we write C implementations of the two most common.C implementations of the two most common.
• Sequential Search in C• Binary Search In C
![Page 20: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/20.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 20
Sequential Search in C
![Page 21: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/21.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 21
![Page 22: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/22.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 22
Binary Search In C
![Page 23: Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 13 Objectives Upon completion you will be able to: Design and implement sequential](https://reader033.vdocuments.us/reader033/viewer/2022061511/56649f505503460f94c72c9b/html5/thumbnails/23.jpg)
Data Structures: A Pseudocode Approach with C, Second Edition 23