You are on page 1of 3

BINARY AND SEQUENTIAL SEARCH DEFINITION SEQUENTIAL SEARCH - The sequential search starts at the first element in the

list and continues down the list until either the item is found or the entire list has been searched. If the wanted item is found, its index is returned. BINARY SEARCH - The binary search starts with the middle element in a list. If that is it, the search is done. If the wanted item is smallerl than the middle item, throw out the last half of the list and search the first half. Otherwise, throw out the first half of the list and search the last half of the list.

Comparison on performance
SEQUENTIAL SEARCH To determine the average number of comparisons in the successful case of the sequential search algorithm: 1. Consider all possible cases. 2. Find the number of comparisons for each case. 3. Add the number of comparisons and divide by the number of cases. If the search item, called the target, is the first element in the list, one comparison is required. If it is the second element in the list, two comparisons are required. If it is the nth element in the list, n comparisons are required.

BINARY SEARCH

Comparison between Sequential and Binary Search:

Sequential Search 1. The sequential search starts at the first element in the list and continues down the list until either the item is found or the entire list has been searched. If the wanted item is found, its index is returned. So it is slow. 2. Sequential search is inefficient because on the average it needs to search half a list to find an item. Binary Search 3. A Binary search is much faster than a sequential search. 4. Binary search works only on an ordered list. 5. Binary search is efficient as it disregards lower half after a comparison.

You might also like