English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

In your own words, describe how the binary search algorithm works. Also, describe a real-life example of using this algorithm

2006-06-06 01:41:28 · 4 answers · asked by David C 2 in Computers & Internet Programming & Design

4 answers

You can do Binary Searching in two ways

1. Using loops.
2.Using recurssion.

What even,Lets now discuss how it works.

It works only in a sorted array or in a sorted sequence.

We are now going to divide the array into two parts using a median or a middle value.Before starting we should need to have a lower bound and an upper bound.

In starting the lower bound value would be zero and the upper bound value should be no . of elements in the array.
median is always (lowerbound+upperbound)/2



Let us set the 'median' as mid and the number you want to search as 'num'

At the first step check mid=num
If so the value is found

else

check num If num set upperbound = mid
and find new mid as
(lowerbound+upperbound)/2

Else if,
num> mid
set lower bound=mid
and find the new mid value,
as
mid=(lowerbound+upperbound)/2


And contine the process until the value is found or the lowerbound=upperbound(Means no element in the array)


I have shown only the concept.
You can do it by using loops,Or by using recurrsion.You can use Divide and Conqure method too(recursive method).

2006-06-06 06:50:45 · answer #1 · answered by DevanamPriyadarshi 3 · 0 0

A binary search algorithm (or binary chop) is a technique for finding a particular value in a linear array, by ruling out half of the data at each step, widely but not exclusively used in computer science. A binary search finds the median, makes a comparison to determine whether the desired value comes before or after it, and then searches the remaining half in the same manner. A binary search is an example of a divide and conquer algorithm (more specifically a decrease and conquer algorithm) and a dichotomic search (more at Search algorithm).

Check the link below for complete details and examples

2006-06-06 01:44:51 · answer #2 · answered by Anonymous · 0 0

You can implement binary search in a number of ways. A normal implementation will find a single item. From that single item you could then expand the found range to include all the equal adjacent items. If you were expecting to find a large range very often you can modify binary search to stop once it's found a range of matches. That range will not necessarily include all the matching items. The algorithmm you use to extend the matching range could simply be a linear search, but could also be a version of binary search itself, perhaps using some information from the initial search.

2016-03-15 01:14:30 · answer #3 · answered by Anonymous · 0 0

maybe this helps?
http://zone.ee/skulldragon/txt/binhex.txt

2006-06-06 01:44:46 · answer #4 · answered by Anonymous · 0 0

1110000111100000111000001111111110000111

2006-06-06 01:44:10 · answer #5 · answered by pratchmg 4 · 0 2

fedest.com, questions and answers