Pergunta de entrevista da empresa Google

Write a Square Root function for a computer without floating point calculations

Respostas da entrevista

Sigiloso

24 de ago. de 2012

Use the babylonian method http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method

3

Sigiloso

18 de ago. de 2012

Use fractions (=2 integers) and the Babylonian/Newtonian approach: X(n+1) = (X(n)^2 + N) / (2 * X(n))

1

Sigiloso

6 de ago. de 2012

Perhaps using binary search will work.

2

Sigiloso

8 de ago. de 2012

By approximation. Star with a = 1 and check if a*a is > N. If so you return a-1 else a++ and move forward. The fact that here we cannot use the floating point calculation makes everything trivial and not much accurate. Anyway convert this strategy into an accurate one using floating point it's easy as well.