Bloomberg LP Interview Question for Software Engineer / Developers






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

{double SquareRoot(int num) {
if(num == 0)
return 0;
if(num == 1)
return 1;

double guess = num/2, oldguess = 0;
while(guess != oldguess) {
oldguess = guess;
guess = (num/guess + guess)/2;
printf("%f %f\n", oldguess, guess);
}
return guess;
}}

- recentKid February 26, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Very Nice Solution...

- Sanjeev Kumar Sawargi March 08, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

it seems like a good solution to begin with but there are three problems:
1. negative numbers
2. real numbers
3. algorithm does not always converge
(try 1.1 for example)
easily solved by having more cases

- no one July 12, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

guess will be never equal to oldguess!

- Anonymous March 27, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It will be, after it crosses sufficient accuracy level

- ampl1f1er April 14, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You can make the accuracy level you want explicit, by saying
while(fabs(guess - oldguess) > Accuracy))
{
....
}

- codemonkey August 16, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

could someone explain the working ? seems greek to me .. :o

- Shiv August 21, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Shiv,

When ever you see algorithm the best way to understand is taking a sample domain value and working on it. If you work on 3-4 values you can esaily understand the logic. Run the algorithm on 4, 16, 64...you ill understand.

- Raj August 22, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

HANDRUN OF THE ABOVE ALGORITHM
For num = 4
guess = 2, oldguess = 0;
guess != oldguess = true
oldguess = 2;
guess = (2 + 2)/2;
printf( 2, 2);

For n= 16
guess = 8, oldguess = 0;
guess != oldguess = true
oldguess = 8
guess = (2+8)/2
printf( 8, 5);

guess != oldguess = true
oldguess = 5
guess = (3+5)/2
printf( 5, 4);

guess != oldguess = true
oldguess = 4
guess = (4+4)/2
printf( 4, 4);

- CyberPhoenix March 29, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There are several numerical techniques for the same, try the bisection method, or the newton raphson technique. There are many other more extensive techniques to approximate variety of functions.

- Ankur July 15, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use Taylor expansion

- Anonymous November 13, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

taylor expansion has sqroot terms in it :(

- wihenao August 25, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use newton raphson technique to find the root of f(x)=x^2-num

- Anonymous November 29, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry, i mean x^2-num=0

- Anonymous November 29, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The algorithm is fine, but how can you expect yourself to be able to figure out this super-smart algorithm during 10-20 minutes in the interview.

I guess any reasonable guessing algorithm will do the job for an interview question.

- Z February 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is my implemenation

double my_sqrt(int x)
{
double start;
double end;
double y;
double prec = 0.0001;

start = 0;
end = x;
y = x/2;

while(y*y < x-prec || y*y > x+prec)
{
if(y*y > x-prec && y*y < x+prec)
break;
else if(y*y > x+prec)
{
end = y;
y = (y+start)/2;
}
else
{
start = y;
y = (y+end)/2;
}
}
return y;
}

- dullboy April 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

g^2=num
2g^2=num+g^2
g^2=num+g^2/2
g=((num/g)+g)/2

- an April 10, 2012 | 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