Chapter # 8 Searching Algorithms
Chapter # 8 Searching Algorithms
Chapter 8
Searching Algorithms
1
6/25/2019
Searching
In computer science, a search algorithm is
An algorithm for finding an item with specified properties
among a collection of items
For Example
Linear Search
Binary Search
Etc…
2
6/25/2019
Linear Search
Linear Search
Is also known as Sequential Search
Mechanism
Search starts at the first element in the list and
Continues until either
The item is found in the list or
The entire list is searched
Feasible for small and unsorted list
Order of the list does not matter
Will have same effect (all orders)
ARRAY-SEARCH(Arr, n, key)
1. for (i=1; i<=n; i++)
2. if A[i]=key
3
6/25/2019
4
6/25/2019
5
6/25/2019
Binary Search
Feasible for large and sorted list/array
Mechanism
Located the middle of the sorted list
Compare the middle value with the search key
If the values are equal – Done !
Otherwise: Eliminate one half of the list after comparison
with the key
Decide; which half of the list contains the key
Repeat the above steps on selected half of the list
The search continues until the key is matched or no element
remain to be searched
Design & Analysis of Algorithms
6
6/25/2019
7
6/25/2019
8
6/25/2019
9
6/25/2019
Design & Analysis of Algorithms
10
6/25/2019
MS Course
Hashing
End of Chapter
11