Binary Search by Zabin

# Binary Search by Zabin - Zabin Visram Room CS115 CS126...

This preview shows pages 1–8. Sign up to view the full content.

CS126 Searching Binary Search

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Binary Search ± Sequential search is not efficient for large lists as it searches half the list, on average ± Another search algorithm – Binary search ± Very fast ± But can only be performed on ordered lists
Example ± If you are looking for you friends number in the phone book, you may decide to look from half way , you know the book is ordered alphabetically therefore if you decide the name is in the right half – you can disregard the left half – throw it away – just concentrate on the right half – this way your search is dramatically reduced – only have ½ book o search – do the same process again – until eventually u either find the name or decide its not there – binary search is the same

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
± When a list is sorted and we have random access to the list as in an array or vector implementation ± we can take advantage of this additional structure in our search methods. ± binary search algorithm uses the “Divide & Conquer” method to search the list
± First the search item is compared with the middle element of the list. If the search item is less than the middle element of the list, we restrict the search to the first half of the list; otherwise we search the second half of the list

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Binary Search ± Consider a sorted list of length 12 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] 4 8 19 25 34 39 45 48 66 75 89 95 list
Binary Search ± Suppose we want to find 75 ± Entire list is searched – compare 75 with middle

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/25/2010 for the course CPE CPE 360 taught by Professor Jenniferchen during the Spring '10 term at Stevens.

### Page1 / 20

Binary Search by Zabin - Zabin Visram Room CS115 CS126...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online