Binary Search

Report 2 Downloads 89 Views
Term 2

Lesson 17

Binary Search

AP Computer Science - Unit Seven

Binary Search

Rule The array must be sorted for this algorithm to work

AP Computer Science - Unit Seven

Binary Search

Steps: Find the middle of the set (low + high)/2 Is this the value? Too low? high = mid-1 Too high? low = mid+1 Repeat until _________ or _________

AP Computer Science - Unit Seven

Binary Search

Repetition Iterative – use a loop Recursive – method calls itself

AP Computer Science - Unit Seven

Binary Search

Advantages: Very fast

Disadvantages: More difficult to code Array must be sorted

AP Computer Science - Unit Seven

Recommend Documents