Practise
Practise
}
public static void main(String args[])
{
int n = Integer.parseInt(args[0]);
System.out.println(fib(n));
}
1
3. Design an algorithm which computes 3n using only c log n instructions for
some positive constant c.
Hint : use the recursive formulation of 3n carefully.
4. Given an array A which stores 0 and 1, such that each entry containing
0 appears before all those entries containing 1. In other words, it is like
{0, 0, 0, ..., 0, 0, 1, 1, ..., 111}. Design an algorithm to find out the small
index i in the array A such that A[i] = 1 using c log n instructions in the
worst case for some positive constant c.
Hint : exploit the idea used in binary search.