-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlgorithm3.java
43 lines (28 loc) · 1 KB
/
Algorithm3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
public class Algorithm3 {
static int count = 0;
static int findNumber(in[] collection, int start, int end, int x) {
count++;
if (end >= start) {
int mid = start + (end - start) / 2;
if (collection[mid] == x)
return mid;
if (collection [mid] > x)
return findNumber(collection, start, mid - 1, x);
retrun findNumber(collection, mid + 1, x);
}
return -1;
}
public static void main(String [] args){
Algorithm3 obj = new Algorithm3();
int[] numColl = new int[10000000];
for(int = 1; i < numColl.length; i++) {
numColl[i] = i;
}
int high = numColl.length - 1;
long startTime = System.currentTimeMillis();
obj.findNumber(numColl, 0, high, 9999997);
System.out.println("We found the values the values at " + count + "try");
long endTime = System.currentTimeMillis();
System.out.println("Total time :: " + (endTime - startTime) + " ms");
}
}