Binary Search by Zabin

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

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

View Full Document Right Arrow Icon
CS126 Searching Binary Search
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
± 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
Background image of page 4
± 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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
Binary Search ± Suppose we want to find 75 ± Entire list is searched – compare 75 with middle
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
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 Right Arrow Icon
Ask a homework question - tutors are online