Algorithms: Search Flashcards

1
Q

Binary Search

A

Binary search is used to find a specified value in a sorted list of items (or if it does not occur in the list, to determine that fact). The idea is to test the element in the middle of the list. If that element is equal to the specified value, you are done. If the specified value is less than the middle element of the list, then you should search for the value in the first half of the list. Otherwise, you should search for the value in the second half of the list. The method used to search for the value in the first or second half of the list is a binary search. That is, you look at the middle element in the half of the list that is still under consideration, and either you’ve found the value you are looking for, or you have to apply binary search to one-half of the remaining elements. And so on!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Pre conditions for Binary Search

A

Array connot be empty and must be sorted in increasing order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly