Pergunta de entrevista da empresa Bloomberg

How to compute square root of integer with only add, sub, div and mult

Respostas da entrevista

Sigiloso

4 de mar. de 2014

f(x)=sqrt(x); 1. Find the integer (n) whose square (x0) is closest to x, e.g: n=sqrt(x0); 2. Use taylor expansion: f(x) = f(x0) + f'(x0)(x-x0) = n + 1/2n*(x-n^2); Verify: x=59; x0=64; n=8; f(59) = 8+1/16*(59-64) =7.6875

3

Sigiloso

23 de set. de 2012

let y(x) = sqrt(x) then guess a value guessY now calculate mean(guessY+x/guessY) which is new guessY keep doing until the relative error < epsilon