@@ -29,7 +29,8 @@ public static final int find(int value, int[] array, boolean optimize) {
2929 BinarySearch .sorted = null ;
3030 }
3131 }
32- 32+ //Recursively find the element
33+ //@return find the element value by recursively
3334 private static int recursiveFind (int value , int start , int end , boolean optimize ) {
3435 if (start == end ) {
3536 int lastValue = sorted [start ]; // start==end
@@ -43,8 +44,10 @@ private static int recursiveFind(int value, int start, int end, boolean optimize
4344 final int middle = low + ((high - low ) / 2 );
4445
4546 final int middleValue = sorted [middle ];
47+ //checks if the middle index is element
4648 if (value == middleValue )
4749 return middle ;
50+ //if value is greater than move to right
4851 if (value > middleValue ) {
4952 if (optimize && (end - middle ) <= SWITCH_TO_BRUTE_FORCE )
5053 return linearSearch (value , middle + 1 , end );
@@ -54,7 +57,10 @@ private static int recursiveFind(int value, int start, int end, boolean optimize
5457 return linearSearch (value , start , middle - 1 );
5558 return recursiveFind (value , start , middle - 1 , optimize );
5659 }
57- 60+ //Linear search to find the element.
61+ //@value the element we want to find.
62+ //@start first index of the array in the array
63+ //@end last index of the array in the array.
5864 private static final int linearSearch (int value , int start , int end ) {
5965 // From index i = start to i = end check if value matches sorted[i]
6066 for (int i = start ; i <= end ; i ++) {
0 commit comments