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.

- gauravk.18 April 07, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

What is the answer?

- jobseeker November 23, 2007 | Flag Reply
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;
}

- Ramu November 23, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hi there this code is true

- Anonymous February 24, 2008 | Flag Reply
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;
}

- algooz April 27, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Great

- Anonymous December 02, 2008 | Flag
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

- gokulprasad June 27, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it is not given that nuber is a perfect square

- thinker June 11, 2012 | Flag
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.)

- gokulprasad June 27, 2008 | Flag Reply
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

- shenwilson July 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

en.wikipedia.org/wiki/Methods_of_computing_square_roots

- russoue February 09, 2010 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More