Please verify jump searching algorithm that I have written and let me know if any bugs are present. I have tested it from my end, but still would like to get it verified for any missing corner scenarios.
class JumpSearch
{
public static void main(String[] args)
{
int[] input = new int[] { 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610 , 670 };
int target = 13;
int output=-1;
int step = (int) Math.floor(Math.sqrt(input.length));
int lastIndex = input.length-1;
int index=step; //directly jump to end of first block.
System.out.println("step : " + step);
System.out.println("start index : " + index);
System.out.println("lastIndex : " + lastIndex);
boolean jumpBlocks = true , endOfInput=false;;
while(jumpBlocks)
{
if(target <= input[index])
{
int previousIndex = (index-step);
System.out.println("previous index : " + previousIndex);
for(int a=index ; a >= previousIndex ; a--)
{
if(input[a] == target)
{
output=a;
break;
}
}
break;
}
else
{
if(endOfInput)
{
jumpBlocks = false;
}
else
{
index += step;
if(index >= lastIndex)
{
endOfInput=true;
index = lastIndex;
}
}
}
}
System.out.println("output : " + output);
}
}