0% found this document useful (0 votes)
49 views4 pages

Bisection Search

The document describes the bisection search method for finding the square root of a number. It works by repeatedly guessing a number in the middle of the current search range and checking if it is too high or too low based on comparing its square to the target number. Each iteration halves the search range to narrow in on the solution. An example demonstrates applying bisection search to find the square root of 25 by iteratively guessing a number, updating the search range, and converging on the solution. The method is effective for problems where the target function value changes monotonically with the input.

Uploaded by

Shivansh Suhane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views4 pages

Bisection Search

The document describes the bisection search method for finding the square root of a number. It works by repeatedly guessing a number in the middle of the current search range and checking if it is too high or too low based on comparing its square to the target number. Each iteration halves the search range to narrow in on the solution. An example demonstrates applying bisection search to find the square root of 25 by iteratively guessing a number, updating the search range, and converging on the solution. The method is effective for problems where the target function value changes monotonically with the input.

Uploaded by

Shivansh Suhane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Bisec&on

search
We know that the square root of x lies
between 0 and x, from mathema&cs
Rather than exhaus&vely trying things star&ng
at 0, suppose instead we pick a number in the
middle of this range
0

x
g

If we are lucky, this answer is close enough

Bisec&on search
If not close enough, is guess too big or too small?
If g**2 > x, then know g is too big; but now search
0

x
new g

And if this new g is, for example, g**2 < x, then know too
small; so now search
0

x
new g

next g

At each stage, reduce range of values to search by half

Example of square root


x = 25!
epsilon = 0.01!
numGuesses = 0!
low = 0.0!
high = x!
ans = (high + low)/2.0!
while abs(ans**2 - x) >= epsilon:!
print('low = ' + str(low) + ' high = ' + str(high) + ' ans = ' + str(ans))!
numGuesses += 1!
if ans**2 < x:!
low = ans!
else:!
high = ans!
ans = (high + low)/2.0!
print('numGuesses = ' + str(numGuesses))!
print(str(ans) + ' is close to square root of ' + str(x))!

Some observa&ons
Bisec&on search radically reduces
computa&on &me being smart about
genera&ng guesses is important
Should work well on problems with ordering
property value of func&on being solved
varies monotonically with input value
Here func&on is g**2; which grows as g grows

You might also like