## Microsoft Interview Question

Comment hidden because of low score. Click to expand.
2
of 2 vote

One of the things that can be done is take the number n whose square root has to be determined. From range 1 to n/2 select a middle element, square it and compare with n.If it comes to be greater than the number n then look into the range 1 to n/4 else look into the range n/2 to n/4. This is kind of binary search and in this way we can determine the appx square root of a number in lg(n) time.

Comment hidden because of low score. Click to expand.
0
of 0 vote

www.mathpath.org/Algor/squareroot/algor.square.root.htm

Comment hidden because of low score. Click to expand.
0
of 0 vote

Courtesy Wikipedia:

float fastsqrt(float val) {
int tmp = *(int *)&val;
tmp -= 1<<23; /* Remove last bit to not let it go to mantissa */
/* tmp is now an approximation to logbase2(val) */
tmp = tmp >> 1; /* divide by 2 */
tmp += 1<<29; /* add 64 to exponent: (e+127)/2 =(e/2)+63, */
/* that represents (e/2)-64 but we want e/2 */
return *(float *)&tmp;
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

hi there this code is true

Comment hidden because of low score. Click to expand.
0
of 0 vote

Let the number be x who's square root we need.
Take a guess at the square root, let it be g.

while(1)
{
g = (1/2)(g + (x/g))
if(g*g == x)
return g;
}

Comment hidden because of low score. Click to expand.
0

Great

Comment hidden because of low score. Click to expand.
0
of 0 vote

add all the odd numbers till u get the number . the number of terms you added is the square root .
For eg.
1=1
4=1+3
9=1+3+5
16=1+3+5+8

Comment hidden because of low score. Click to expand.
0

it is not given that nuber is a perfect square

Comment hidden because of low score. Click to expand.
0
of 0 vote

the above can be used only to get square root as a whole number only (not a float number.)

Comment hidden because of low score. Click to expand.
0
of 0 vote

User Newton Iteration, first find a initial solution f0, then compute f1, f2, ...., when abs(fi - fi-1) < epislon, algorithm end, return fi

Comment hidden because of low score. Click to expand.
0
of 0 vote

en.wikipedia.org/wiki/Methods_of_computing_square_roots

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.