Solution: using newton method:
Solving f(x) = 0, using iterative method: x_1 = x_0 - f(x_0) / f'(x_0).
So the iterative for sqrt(n) is
y = x/2 + N/(2x)
Implementation:
x = 2^ceil(numbits(N)/2)
loop:
y = floor((x + floor(N/x))/2)
if y >= x
return x
x = y
Tuesday, March 19, 2013
Subscribe to:
Post Comments (Atom)
Manacher's Longest Palindromic Substring Algorithm
http://manacher-viz.s3-website-us-east-1.amazonaws.com/#/
-
Given two words ( start and end ), and a dictionary, find the length of shortest transformation sequence from start to end , such tha...
-
Suppose a bus is running on a loop route. It takes 10 mins for the bus to finish the route. If a guy arrives at a bus stop at uniformly rand...
-
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, ...
No comments:
Post a Comment