154k views
4 votes
The code segment below prints some of the elements in an array with size n. Select an expression to

complete the code segment so that the resulting algorithm has O(log n) running time.

for __________________________

System.out.println(array[j]);

User Morti
by
5.8k points

1 Answer

4 votes

Answer:

int j = 1; j < array.length; j =j *2

Step-by-step explanation:

j=j*2 loops have O(logn) so the running time of algorithm is O(logn).

User Nicu Stiurca
by
6.0k points