Program: 92604
Project: 92604
Buggy source:
/** 
 * Solution implemented to calculate the square root of a given number based on an iterative algorithm. First, we are going to find the first number witch square is greater than the number. Once we have that number we are going to apply a binary search between candidate and candidate +1. The complexity order in space terms of this algorithm is O(1) because we are not using any additional data structure. The complexity order in time terms is more difficult to calculate T(N) = T(N/2) + c  where as N is step length. Which is 1 initially. 0.5 after that. 0.25 after that Stopping condition of this recurrence relation is dependant on delta. If it is 0, then time complexity is infinite So we won't be able to calculate the exact time complexity using master's theorem. Time complexity of this algorithm is inversly proportional to square root of Delta As square root is an irrational number for non square numbers. But here, it will be function of delta and precision of the variables used. Which is difficult to calculate.
 */
public float calculateSquareRootIterative(int number){
  float candidate=1f;
  while (candidate * candidate <= number) {
    candidate++;
  }
  candidate--;
  if (isGoodResultForSqrt(number,candidate * candidate)) {
    return candidate;
  }
  float top=candidate + 1;
  float bottom=candidate;
  float newCandidate=(top + bottom) / 2;
  float result=newCandidate * newCandidate;
  while (!isGoodResultForSqrt(number,result)) {
    if (result > number) {
      top-=0.1f;
    }
 else {
      bottom-=0.1f;
    }
    newCandidate=(top + bottom) / 2;
    result=newCandidate * newCandidate;
  }
  return Math.abs(newCandidate);
}

Fixed version (ground truth):
/** 
 * Solution implemented to calculate the square root of a given number based on an iterative algorithm. First, we are going to find the first number witch square is greater than the number. Once we have that number we are going to apply a binary search between candidate and candidate +1. The complexity order in space terms of this algorithm is O(1) because we are not using any additional data structure. The complexity order in time terms is more difficult to calculate T(N) = T(N/2) + c  where as N is step length. Which is 1 initially. 0.5 after that. 0.25 after that Stopping condition of this recurrence relation is dependant on delta. If it is 0, then time complexity is infinite So we won't be able to calculate the exact time complexity using master's theorem. Time complexity of this algorithm is inversly proportional to square root of Delta As square root is an irrational number for non square numbers. But here, it will be function of delta and precision of the variables used. Which is difficult to calculate.
 */
public float calculateSquareRootIterative(int number){
  float candidate=1f;
  while (candidate * candidate <= number) {
    candidate++;
  }
  candidate--;
  if (isGoodResultForSqrt(number,candidate * candidate)) {
    return candidate;
  }
  float top=candidate + 1;
  float bottom=candidate;
  float newCandidate=(top + bottom) / 2;
  float result=newCandidate * newCandidate;
  while (!isGoodResultForSqrt(number,result)) {
    if (result > number) {
      top-=0.1f;
    }
 else {
      bottom+=0.1f;
    }
    newCandidate=(top + bottom) / 2;
    result=newCandidate * newCandidate;
  }
  return Math.abs(newCandidate);
}