Bloomberg LP Interview Question Financial Software Developers
0of 0 votesHow to search a number among a lot of numbers. I asked if it is one time thing. Answer is yes. Then I did sequential search; Then he said how about search another one....
Then I said sort these numbers first and suggest binary tree.
Wrote down the binary search code
Why not use a Hash?
Is using external memory a case?
Hash will give you the number at one shot

Maybe they wanted to check what kind of questions to ask given such a simple requirement.
- Chander Shivdasani on February 04, 2011 Edit | Flag ReplyAlso, there is a glitch in the implementation of Binary Search, specially when we do
mid = (low + high)/2
If the numbers are really large, the sum of (low + high) would overflow and cycle to a negative number.
One work around is to use
mid = low + (high - low)/2
HTH,
Chander